文件上传C#后有时PDF文件被损坏 [英] Some times PDF files get corrupted after File Upload C#

查看:458
本文介绍了文件上传C#后有时PDF文件被损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图上传PDF文件。只有有时上传的文件被损坏。当我在Adobe或浏览器上打开该文件。它说图片数据不足



这个问题不适用于所有的上传。当我试图再次上传相同的文件的作品完美。
我无法复制这个问题,所以我可以知道为什么这种类型的问题发生
我使用下面的代码来保存文件



<$ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆