Introduction:
Here I will explain how to solve problem of “e: is a physical path but a virtual path was expected” in asp.net using c#, vb.net. Generally this physical and virtual path problem occurred whenever we refer “Server.MapPath” value multiple times while using folder path in applications. To solve this e:is a physical path but a virtual path was expected we need to use Server.MapPath only once while getting or inserting files in folder in asp.net using c#, vb.net.
Description:
I
hope it helps you to fix your “e: is a physical
path but virtual path was expected” in c#, vb.net. Happy Coding……
Here I will explain how to solve problem of “e: is a physical path but a virtual path was expected” in asp.net using c#, vb.net. Generally this physical and virtual path problem occurred whenever we refer “Server.MapPath” value multiple times while using folder path in applications. To solve this e:is a physical path but a virtual path was expected we need to use Server.MapPath only once while getting or inserting files in folder in asp.net using c#, vb.net.
Description:
In
previous posts I explained export gridview data to excel in windows application, auto suggestions search textbox in master page in asp.net, download multiple files as zip folder
in asp.net
and many articles relating to solve errors in asp.net, SQL
Server, IIS, etc. Now I will
explain how to solve problem of “e: is a physical path but a virtual path
was expected” in asp.net using c#, vb.net.
When
I run following code I got error like physical path but a virtual path was
expected in asp.net using c#, vb.net application
HttpPostedFile file =
files[i];
string fname;
fname = file.FileName;
string strpath =Server.MapPath("~/images/") + tutorial;
if (!(Directory.Exists(strpath)))
{
Directory.CreateDirectory(strpath);
}
DataSet _ds = new DataSet();
_ds = CommonMethods.Getdataset("insertimagedetails", "insertedimages");
if (!string.IsNullOrEmpty(_ds.Tables[0].Rows[0][0].ToString()))
{
imgids += _ds.Tables[0].Rows[0][0].ToString()+",";
fname = Path.Combine(Server.MapPath(strpath),
fname);
file.SaveAs(fname);
}
|
When
I run above code I got problem like “physical path but a virtual path was
expected in asp.net” because I already got physical path
for strpath parameter initial itself
again while saving in folder I am trying to get physical path from already
available path that’s why this problem occurred.
To
fix this problem we need to use only one physical path for that we need to
remove “Server.MapPath” from folder
path like as shown below
HttpPostedFile file =
files[i];
string fname;
fname = file.FileName;
string strpath =Server.MapPath("~/images/") + tutorial;
if (!(Directory.Exists(strpath)))
{
Directory.CreateDirectory(strpath);
}
DataSet _ds = new DataSet();
_ds = CommonMethods.Getdataset("insertimagedetails", "insertedimages");
if (!string.IsNullOrEmpty(_ds.Tables[0].Rows[0][0].ToString()))
{
imgids += _ds.Tables[0].Rows[0][0].ToString()+",";
fname = Path.Combine(strpath,
fname);
file.SaveAs(fname);
}
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
2 comments :
hi sir,
im facing the same problem can u pls send full code
Super Sir
Note: Only a member of this blog may post a comment.