0
我使用Ajax的异步文件上传到抓取的图像文件,并将其保存到一个文件夹空文件:ASP.net文件上传保存
if(file != null && file.hasFile)
{
if(file is the appropriate file type)
{
if(the filename is already taken)
{
add random numbers on the file name until it's unique
}
file.SaveAs(filepath + filename);
}
}
这是我的本地计算机上的伟大工程。但是,当我将程序发布到服务器时,文件将以正确的名称保存在正确的位置,但文件大小为0.我无法打开文件。
我在做什么错?
这是我真正的代码:
// If cert has a file
if(cert != null && cert.HasFile)
{
// If cert is the appropriate file type
if((cert.FileName.IndexOf(".jpg", StringComparison.OrdinalIgnoreCase) < 0) &&
(cert.FileName.IndexOf(".jpeg", StringComparison.OrdinalIgnoreCase) < 0) &&
(cert.FileName.IndexOf(".tiff", StringComparison.OrdinalIgnoreCase) < 0) &&
(cert.FileName.IndexOf(".png", StringComparison.OrdinalIgnoreCase) < 0) &&
(cert.FileName.IndexOf(".gif", StringComparison.OrdinalIgnoreCase) < 0) &&
(cert.FileName.IndexOf(".pdf", StringComparison.OrdinalIgnoreCase) < 0))
{
// Popup warning
Session["imagePopup"] = "true";
}
else
{
string filename = cert.FileName;
// If image already exists randomly add numbers until a unique filename is found
while(File.Exists(System.Configuration.ConfigurationManager.AppSettings["CertificateSavePath"] + filename))
{
Random r = new Random();
filename = filename.Insert(0, r.Next(99).ToString());
}
// Save the new file
try
{
// save the file
cert.SaveAs(System.Configuration.ConfigurationManager.AppSettings["CertificateSavePath"] + filename);
}
catch(Exception ex)
{
error.Text += ex.Message + "<br />";
}
根据您的伪代码,一切都很好......所以,如何向我们展示*真正的代码*呢? – Blachshma 2013-03-13 19:42:02
这听起来像一个权限问题。你可以仔细检查你的应用程序在IIS下运行的进程是否有权写入和修改你要保存的文件夹中的文件? – jadarnel27 2013-03-13 20:17:43