0

ファイルをデータベースに保存するときに/~/文字を削除する方法に問題があります。問題は、ファイルアップロードコントローラーにファイルがない場合です。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));
}
4

1 に答える 1

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);
于 2013-05-16T19:49:54.190 に答える