I am trying to upload PDF files. Only sometimes uploaded file gets corrupt. When I open that file on Adobe or browser. it says Insufficient data for images.
This problem is not for all the uploads. When I tried to upload the same file again its works perfectly. I am not able to replicate the issue so that I can know why this type of issue occurring I am using below code to save the file
FileUpload upload = GridView1.Rows[index].FindControl("FileUpload1") as FileUpload;
if (upload.HasFile)
{
string nameoffile = upload.FileName;
Random ran = new Random();
int forReference = ran.Next();
string[] strfileArray = nameoffile.Split('.');
nameoffile = strfileArray[0] + "" + forReference + ".pdf";
upload.SaveAs(path + "/" + nameoffile);
}
else
{
upload.SaveAs(path + "/" + nameoffile);
}
Note: We are running this appliaction on Azure VM. This code was works without any issue on previous server. since we migrated to Azure Windows server
Narasappa C J
ravi.jadiyannavar@gmail.com
Pls Mark This Post As Answer If it Helps U..
If no file is posted for the current row, it seems you are reusing the last file name possibly overwriting the previous file? The next time it happens I would check the size of the file to see if it is 0.
Member
582 Points
494 Posts
Some times PDF files get corrupted after File Upload C# Azure VM
Jun 12, 2017 05:57 AM|narasappa|LINK
I am trying to upload PDF files. Only sometimes uploaded file gets corrupt. When I open that file on Adobe or browser. it says Insufficient data for images.
This problem is not for all the uploads. When I tried to upload the same file again its works perfectly. I am not able to replicate the issue so that I can know why this type of issue occurring I am using below code to save the file
FileUpload upload = GridView1.Rows[index].FindControl("FileUpload1") as FileUpload; if (upload.HasFile) { string nameoffile = upload.FileName; Random ran = new Random(); int forReference = ran.Next(); string[] strfileArray = nameoffile.Split('.'); nameoffile = strfileArray[0] + "" + forReference + ".pdf"; upload.SaveAs(path + "/" + nameoffile); } else { upload.SaveAs(path + "/" + nameoffile); } Note: We are running this appliaction on Azure VM. This code was works without any issue on previous server. since we migrated to Azure Windows server
ravi.jadiyannavar@gmail.com
Pls Mark This Post As Answer If it Helps U..
All-Star
48270 Points
17981 Posts
Re: Some times PDF files get corrupted after File Upload C# Azure VM
Jun 12, 2017 11:10 AM|PatriceSc|LINK
Hi,
If no file is posted for the current row, it seems you are reusing the last file name possibly overwriting the previous file? The next time it happens I would check the size of the file to see if it is 0.