Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to specify a rooted path?

Posted on 2011-03-24
2
979 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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