Solved

How to specify a rooted path?

Posted on 2011-03-24
2
1,040 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 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