alicia1234
asked on
How to specify a rooted path?
I am using <input type="file" id="grpImage" runat="server" /> on a form to let the user upload an image.
In the code-behind, I am trying to save the image on the server to the /uploadedimages directory in my site. (See code below).
The save path is coming out as "c:\uploadedimages\group_1 234.jpg" - note the "c:" being tacked on to the front. So I get an error " Could not find a part of the path .. ".
So then I tried setting the image name like this (with the ~):
string imgName = "~/uploadedimages/group_" + strGroupId + "." + fileExt;
But that gives this error:
The SaveAs method is configured to require a rooted path, and the path '~/uploadedimages/group_42 94967302.j pg' is not rooted.
What's the correct syntax to use?
In the code-behind, I am trying to save the image on the server to the /uploadedimages directory in my site. (See code below).
The save path is coming out as "c:\uploadedimages\group_1
So then I tried setting the image name like this (with the ~):
string imgName = "~/uploadedimages/group_" + strGroupId + "." + fileExt;
But that gives this error:
The SaveAs method is configured to require a rooted path, and the path '~/uploadedimages/group_42
What's the correct syntax to use?
if (grpImage.PostedFile.FileName != "")
{
string fileNamePath = grpImage.PostedFile.FileName;
string fileExt = "jpg"; // need logic here to parse the filename to get it
string imgName = "/uploadedimages/group_" + strGroupId + "." + fileExt;
grpImage.PostedFile.SaveAs(imgName);
updatedGroup.GroupImage = "/uploadedimages/skiing_club.jpg";
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER