Reputation: 1
System.IO.Path.GetFullPath (FileUpload1.PostedFile.FileName);
Path.GetFileName (FileUpload1.PostedFile.FileName);
System.IO.Path.GetDirectoryName (FileUpload1.PostedFile.FileName).ToString ();
Convert.ToString (System. IO. Directory. GetParent (FileUpload1.PostedFile.FileName));
This code did not take File location path. It is taken this path C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\DevServer\\10.0\\kathir.doc
, but cautious document file is stored in D: drive... Please help how to get the correct path.
My Code
public string GetDataFromFile1()
{
string str = string.Empty;
if (FileUpload.PostedFile.ContentLength < 512000)
{
string filename = Path.GetFileName(FileUpload.FileName);
FileUpload.SaveAs(Server.MapPath("~/") + filename);
string filepath = Path.GetFullPath(FileUpload.PostedFile.FileName);
DocToText docToText = new DocToText(filepath);
string Extension = Path.GetExtension(this.FileUpload.PostedFile.FileName);
switch (Extension.ToUpper())
{
case ".DOC":
ResumeContent = docToText.Extract();
break;
case ".DOCX":
ResumeContent = docToText.Extract();
break;
case ".PDF":
ResumeContent = docToText.ExtractPDFtoWord();
break;
default:
break;
}
str = "File uploaded successfully!";
}
return str;
}
Upvotes: 0
Views: 5349
Reputation: 156948
I think the issue is in this line:
string filepath = Path.GetFullPath(FileUpload.PostedFile.FileName);
You need to use the value from the previous row, like this:
string path = Server.MapPath("~/") + filename;
FileUpload.SaveAs(path);
string filepath = Path.GetFullPath(path);
Maybe the last line is now unnecessary.
Upvotes: 1