Reputation:
I have problem how to remove /~/ character from when I save file into database my problem is when they are no file into file upload controller I grape the NavigateUrl form asp hyper link and add to savePath to save it but I get exception it couldn't find the directory
Could not find a part of the path '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));
}
Upvotes: 0
Views: 115
Reputation: 102753
You could use something like this to get the path:
// 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);
Upvotes: 1