我有问题如何从我将文件保存到数据库时删除/〜/字符我的问题是当他们没有文件到文件上传控制器我葡萄NavigateUrl表单asp超链接并添加到savePath保存但我得到例外,它无法找到目录
无法找到路径的一部分'C:\ inetpub \ wwwroot \ ideaPark \ DesktopModules \ ResourceModule \ pdf_resources \〜\ DesktopModules \ ResourceModule \ pdf_resources \ New Text Document.txt'。
//save pdf docs
String savePathPDF_Resouce = @"~/DesktopModules/ResourceModule/pdf_resources/";
String savePathPDF_Vocab = @"~/DesktopModules/ResourceModule/pdf_resources/";
if (fuPDFDoc.HasFile || fupdfVocabularyURL.HasFile)
{
String fileName = fuPDFDoc.FileName;
String fileName_Vocab = fupdfVocabularyURL.FileName;
savePathPDF_Resouce += fileName;
savePathPDF_Vocab += fileName_Vocab;
fuPDFDoc.SaveAs(Server.MapPath(savePathPDF_Resouce));
fupdfVocabularyURL.SaveAs(Server.MapPath(savePathPDF_Vocab));
}
else
if (!fuPDFDoc.HasFile || !fupdfVocabularyURL.HasFile)
{
savePathPDF_Resouce += hl_doc_res.NavigateUrl.ToString();
savePathPDF_Vocab += hl_doc_vocab.NavigateUrl.ToString();
fuPDFDoc.SaveAs(Server.MapPath(savePathPDF_Resouce));
fupdfVocabularyURL.SaveAs(Server.MapPath(savePathPDF_Vocab));
}
答案 0 :(得分:1)
您可以使用类似的东西来获取路径:
// root filesystem path for the application (C:\inetpub\wwwroot\ideaPark)
string virtualPathRoot = AppDomain.CurrentDomain.BaseDirectory;
// path relative to the application root (/DesktopModules/ResourceModule/pdf_resources/)
string relativePath = savePathPDF_Resouce.TrimStart("~");
// save here
string targetPath = Path.Combine(virtualPathRoot, relativePath);