文件上传C#后有时PDF文件被损坏 [英] Some times PDF files get corrupted after File Upload C#
问题描述
这个问题不适用于所有的上传。当我试图再次上传相同的文件的作品完美。
我无法复制这个问题,所以我可以知道为什么这种类型的问题发生
我使用下面的代码来保存文件
<$ FileUpload upload = GridView1.Rows [index] .FindControl(FileUpload1)作为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);
注意:我们在Azure虚拟机上运行这个应用程序。这个代码在以前的服务器上没有任何问题。因为我们已经迁移到Azure上了。我们曾经在Azure虚拟机的C盘上托管过应用程序。将应用程序更改为辅助存储后,即D驱动器问题得到解决
I am trying to upload PDF files. Only sometimes uploaded file gets corrupt. When I open that file on Adobe or browser. its says Insufficient data for an 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
We had hosted application on C drive of azure VM. After Changing application to secondary storage i.e. D drive problem got resolved
这篇关于文件上传C#后有时PDF文件被损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!