lundi 25 avril 2016

asp net error the process cannot access the file because it is being used

Hi I have an error with regards to the subject above, basically I am just downloading a file from it's path. My download code is this

string sFile = Request.QueryString["RFBNumber"].ToString();
        string sFile2 = Request.QueryString["FolderName"].ToString();
        string sFlag = Request.QueryString["Flag"].ToString();

        //CreateRFBReport(sFile, sFile2);
        //CreateSingleFile(sFile2, sFile);
        if(sFlag == "1")
        {
            sFilename = "RFB_" + sFile + "_COLLATED.PDF";
            sGlobalFolderName = sFile2;
            sFilePath = @"" + sGlobalFolderName + "\\" + sFilename;

            WebClient client = new WebClient();
            byte[] buff = client.DownloadData(sFilePath);
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", buff.Length.ToString());
            Response.BinaryWrite(buff);
        }
        if(sFlag == "2")
        {
            sFilename = "SOP_" + sFile + "_COLLATED.PDF";
            sGlobalFolderName = sFile2;
            sFilePath = @"" + sGlobalFolderName + "\\" + sFilename;

            WebClient client = new WebClient();
            byte[] buff = client.DownloadData(sFilePath);
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", buff.Length.ToString());
            Response.BinaryWrite(buff);
        }

I have to refresh the page multiple times before I can download the item, I am having an error on the line byte[] buff = client.DownloadData(sFilePath);

Can anyone help me please? Been searching a way to solve this issue. Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire