Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to uplad file to specific location using asp.net webservice .When I writing this:

byte[] file = FileUpload1.FileBytes;
and passing webservice,webservice works fine.Client can be windows service may not web application.File path can be sent to service.From file path,I want to convert to byte array.So I used

byte[] array = File.ReadAllBytes("C:\\Users\\riya\\Desktop\\sample.txt");
But it is not working.Array always contain zero{byte[0]}.How to handle this?

What I have tried:

byte[] array = File.ReadAllBytes("C:\\Users\\riya\\Desktop\\sample.txt");
Posted
Updated 20-Oct-16 20:22pm

1 solution

The problem is that a Service doesn't run under your userID - it runs under a system user that doesn't have access to your user's data. And since that file is on a user's desktop, the service doesn't have any access to it. As a result, the ReadAllBytes call will throw an exception and your code is presumably catching that and replacing it with an empty array.
Move your file to a different folder, and ensure that all users have access to the files it contains.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900