Reputation: 1905
Hi all i am uploading the files uploaded by the user in this path
string savefilename = Path.Combine(Server.MapPath("~/Content/UploadedFiles/"),
Path.GetFileName());
And i am saving the Url in the Database in the Url Column in this
~/Content/UploadedFiles/BugTrackerDataBase.xlsx
and i am trying to retrieve the file Uploaded by the user by a link in my grid view my retrieve method looks like this
public ActionResult ViewAttachments(string AttachmentName)
{
try
{
AttachmentName = Session["AttachmentUrl"].ToString();
var fs = System.IO.File.OpenRead(Server.MapPath("'" + AttachmentName + "'"));
return File(fs, "application/doc", AttachmentName);
}
catch
{
throw new HttpException(404, "Couldn't find " + AttachmentName);
}
}
and i have the Excepiton
"Could not find a part of the path 'D:\AnilWork\BugTracker\BugTracker\ViewBug\'UploadedFiles\BugTrackerDataBase.xlsx''."
can any one tell me where am i doing wrong or the write procedure to do this
Upvotes: 0
Views: 383
Reputation: 623
try
var fs = System.IO.File.OpenRead(Server.MapPath(" + AttachmentName + "));
instead of
var fs = System.IO.File.OpenRead(Server.MapPath("'" + AttachmentName + "'"));
it shoud be replaced with (Server.MapPath(""+ AttachmentName + ""))
Upvotes: 1
Reputation: 656
That is because you have " ' " in your path.
\BugTracker\ViewBug\'UploadedFiles\BugTrackerDataBase.xlsx''
Remove them an it should work. Like this
var fs = System.IO.File.OpenRead(Server.MapPath(AttachmentName));
Upvotes: 2