Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to specify a rooted path?

Posted on 2011-03-24
2
Medium Priority
?
1,192 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
[X]
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
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 1000 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 .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 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