Server.MapPath() Problem!!!
-
Dear Friends, I want to open a file on the click of a link in the Grid named as VIEW. The path I am binding to is the local path i.e., ~/Documents/ScanDoc/[FileName] but when i am opening it on the local server; I am getting the error as follows:- File does not exist. System.Web.HttpException: File does not exist. at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response) at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context) at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
But when I updated the PathColumn in database with this value:-"http://localhost:1383/~/Document/ScanDoc/\[FileName\]" which is actually being saved as "Documents/ScanDoc/[FileName]", the thing worked and i was able to see the file when i clicked on the link. Now my problem is that how could i bind "http://localhost:1383/~" path to "Documents/ScanDoc/[FileName]" which is being saved in the database. ThanksVarun Sareen (Dot Net Developer)
-
Dear Friends, I want to open a file on the click of a link in the Grid named as VIEW. The path I am binding to is the local path i.e., ~/Documents/ScanDoc/[FileName] but when i am opening it on the local server; I am getting the error as follows:- File does not exist. System.Web.HttpException: File does not exist. at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response) at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context) at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
But when I updated the PathColumn in database with this value:-"http://localhost:1383/~/Document/ScanDoc/\[FileName\]" which is actually being saved as "Documents/ScanDoc/[FileName]", the thing worked and i was able to see the file when i clicked on the link. Now my problem is that how could i bind "http://localhost:1383/~" path to "Documents/ScanDoc/[FileName]" which is being saved in the database. ThanksVarun Sareen (Dot Net Developer)
Just grab the Url Authority like
String UrlAuthority = String.Format("http://{0}",Request.Url.Authority);
Now make a string of your static path
String Path = "Documents/ScanDoc/[FileName]";
Combine both for final Output
String FullPath = Path.Combine(UrlAuthority,Path);
And you're done.
Regards, Hiren.
My Recent Article: - Way to know which control have raised a postback
My Recent Tip/Trick: - The ?? Operator. -
Just grab the Url Authority like
String UrlAuthority = String.Format("http://{0}",Request.Url.Authority);
Now make a string of your static path
String Path = "Documents/ScanDoc/[FileName]";
Combine both for final Output
String FullPath = Path.Combine(UrlAuthority,Path);
And you're done.
Regards, Hiren.
My Recent Article: - Way to know which control have raised a postback
My Recent Tip/Trick: - The ?? Operator.Thanks Hiren, the thing you told worked
Varun Sareen (Dot Net Developer)
-
Thanks Hiren, the thing you told worked
Varun Sareen (Dot Net Developer)
Glad it helped you. You can always rate Answer if it helped you.
Regards, Hiren.
My Recent Article: - Way to know which control have raised a postback
My Recent Tip/Trick: - The ?? Operator.