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
pg' is not rooted.
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;
updatedGroup.GroupImage = "/uploadedimages/skiing_club.jpg";