Solved

How to specify a rooted path?

Posted on 2011-03-24
2
937 Views
Last Modified: 2012-08-14
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_1234.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_4294967302.jpg' 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;
            grpImage.PostedFile.SaveAs(imgName);
            updatedGroup.GroupImage = "/uploadedimages/skiing_club.jpg";
        }

Open in new window

0
Comment
Question by:alicia1234
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 250 total points
ID: 35208003
string imgName = Server.MapPath("~/uploadedimages/group_" + strGroupId + "." + fileExt);

Hope that helps.
0
 

Author Comment

by:alicia1234
ID: 35209670
Perfect! Thank you!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now