You must Sign In to post a response.
  • Category: ASP.NET

    File.ReadAllBytes() return {byte[0]}

    I want to uplad file to specific location using 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?
  • #768403
    Try this

    byte[] fileBytes = new byte[] { };
    fileName = "sample.txt";
    fileBytes = System.IO.File.ReadAllBytes("C:\\Users\\riya\\Desktop\\sample.txt");

    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);

    Software Developer
    iFour Technolab Pvt. Ltd.

  • #768408
    Please check that server has access to provided 'File path'.
    Here server means where your service is hosted.

  • Sign In to post your comments