文件未发现异常,一旦部署到服务器 [英] File not found exception once deployed to Server
问题描述
我使用的是低于code上传图片文件到SharePoint文档库。在code正常工作,但在本地一旦部署到服务器时,我得到的异常找不到文件。
I am using the below code to Upload an Image file to a SharePoint Document Library. The code works fine locally but once deployed to server, i get the Exception as file not found.
String fileToUpload = FlUpldImage.PostedFile.FileName; //@"C:\Users\admin.RSS\Desktop\Photos\me_skype.jpg";
String documentLibraryName = "SiteAssets";
if (!System.IO.File.Exists(fileToUpload))
throw new FileNotFoundException("File not found.", fileToUpload);
SPFolder myLibrary = web.Folders[documentLibraryName];
// Prepare to upload
Boolean replaceExistingFiles = true;
String fileName = CheckStringNull(txtFirstName.Text) + CheckStringNull(txtLastName.Text) + CheckDateNull(txtDOB) + System.IO.Path.GetFileName(fileToUpload); ;
if (fileName.Contains('/'))
{
fileName = fileName.Replace("/", "");
}
if (fileName.Contains(':'))
{
fileName = fileName.Replace(":", "");
}
FileStream fileStream = File.OpenRead(fileToUpload);
//Upload document
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
string url = site.ToString() + "/" + spfile.ToString();
if (url.Contains("="))
{
url = url.Split('=')[1];
}
//Commit
myLibrary.Update();
的字符串文件上传包含URL为 C:\\用户\\ admin.RSS \\桌面\\照片\\ me.jpg
此URL实际上是客户端系统和服务器端code抛出异常,因为没有找到文件。如何处理这个问题呢?
The string fileupload contains URL as C:\Users\admin.RSS\Desktop\Photos\me.jpg
This URL is actually the client system and the server side code throws exception as file not found. How to handle this issue?
更新:
我删除code的来检查,如果该文件存在,现在我得到的FileStream FILESTREAM = File.OpenRead(fileToUpload)的exeption线;
为 C:\\ WINDOWS \\ SYSTEM32 \\ INETSRV \\ 20120605_133145.jpg感冒没有找到
I removed the lines of code that checks if the file exists and now i get the exeption on FileStream fileStream = File.OpenRead(fileToUpload);
as c:\windows\system32\inetsrv\20120605_133145.jpg cold not be found
请帮助。谢谢
推荐答案
将文件保存到物理服务器和比对同一工作帮助我解决我的问题。
Saving the file physically onto server and than working on the same helped me resolve my issue.
这篇关于文件未发现异常,一旦部署到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!