I have a web service that renders PDF from server and converts it into byte stream.

The problem I am encountering is that the web method is not working when hosted on IIS and I don't know what might be the problem because I am not in c#. I just want the response of it and need to display in my android app. The error I get is:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\VAT Publishing\Android_web_service\App_Data\Order_Copy\303900816_Appl_Application.pdf'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at officer_auth.GetFile(String filename)

and my code is as follows

 public byte[] GetFile(string filename)
{
   // byte[] binFile = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
    string src = "\\\\182.10.0.10\\d$\\abc_Files\\" + filename.ToString();
    string dest = Server.MapPath("~/App_Data/Order_Copy/") + "\\" + filename.ToString();
    FileInfo theFile = new FileInfo(src);
    try
    {
        foreach (string file1 in Directory.GetFiles(Server.MapPath("~/App_Data/Order_Copy/"), "*.pdf"))
        {
            try { File.Delete(file1); }
            catch { }
        }
    }
    catch
    { }
    if (theFile.Exists)
    {
        File.Copy(src, dest);

    }


    BinaryReader binReader = new BinaryReader(File.Open(Server.MapPath("~/App_Data/Order_Copy/") + "\\" + filename.ToString(), FileMode.Open, FileAccess.Read));
    binReader.BaseStream.Position = 0;
    byte[] binFile = binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length));
    binReader.Close();
    return binFile;
}

Related posts

Recent Viewed