【发布时间】:2012-02-01 04:42:55
【问题描述】:
我有一个返回 c# 代码来保存服务器文件夹中的文件并从该位置检索保存的文件。但是这段代码在本地机器上运行良好。但是在 IIS 中托管应用程序后,我可以将文件保存在所需的位置。但我无法使用
从该位置检索文件Process.Start
会有什么问题?我在谷歌搜索过,我知道这可能是由于访问权限。但我不知道确切的问题是什么以及如何解决这个问题?任何人请帮我解决这个问题?
保存文件:
string hfBrowsePath = fuplGridDocs.PostedFile.FileName;
if (hfBrowsePath != string.Empty)
{
string destfile = string.Empty;
string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\\\";
if (!Directory.Exists(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1)))
Directory.CreateDirectory(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1));
FileInfo FP = new FileInfo(hfBrowsePath);
if (hfFileNameAutoGen.Value != string.Empty)
{
string[] folderfiles = Directory.GetFiles(FilePath);
foreach (string fi in folderfiles)
File.Delete(fi);
//File.Delete(FilePath + hfFileNameAutoGen.Value);
}
hfFileNameAutoGen.Value = PONumber + FP.Extension;
destfile = FilePath + hfFileNameAutoGen.Value;
//File.Copy(hfBrowsePath, destfile, true);
fuplGridDocs.PostedFile.SaveAs(destfile);
}
要检索文件:
String filename = lnkFileName.Text;
string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\";
FileInfo fileToDownload = new FileInfo(FilePath + "\\" + filename);
if (fileToDownload.Exists)
Process.Start(fileToDownload.FullName);
【问题讨论】:
-
“不工作”是什么意思?会发生什么?
-
您如何在服务器文件夹中保存文件并从该位置检索保存的文件,提供代码。还有你在
Process.Start做什么@ -
记录错误信息,粘贴到这里;也许您在共享主机上存在部分信任问题。
-
嗨,我已经添加了保存和检索文件的代码。请再次检查我的问题。
-
建议:使用
Path.Combine创建文件或文件夹路径
标签: c# asp.net visual-studio-2008 iis