I need a Server.MapPath advice

J

Jeff

Hey

asp.net 2.0

The code below saves the "helloworld.jpeg" file to:
C:\Documents and Settings\Jeff\My Documents\Visual Studio
2005\WebSites\BN\webForms\Profile

HttpPostedFile file = fuPicture.PostedFile;
byte[] data = new byte[file.ContentLength];
file.InputStream.Read(data, 0, file.ContentLength);
Profile.Picture = data;
Profile.PictureType = file.ContentType;
//This is just a test:
System.IO.MemoryStream mstream = new System.IO.MemoryStream();
mstream.Write(data, 0, data.Length);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
bmp.Save(Server.MapPath("helloworld.jpeg"),
System.Drawing.Imaging.ImageFormat.Jpeg);
mstream.Close();

\webForms is a subfolder in my project
\webForms\Profile is the folder which contains the form which execute the
code above....

This works but this isn't good solution because it gives the physical path
to the file on my devbox and I'm not sure I can use this on a live server...

How can I specify that for example the files generated should be saved to
"\image\" in my project folder (relative path)....??

I wonder because I want to save the path to the file in user's Profile and
are looking for the best way of specifying the path...

any suggestions?

Jeff
 
K

Ken Cox [Microsoft MVP]

Hi Jeff,

In ASP.NET syntax, the tilde (~) represents the root of the web. Therefore,
to get to the root and back down to the image folder, try this:

Server.MapPath("~/image/file.jpg")

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
 
J

Jeff

Thanks, it works great...


Ken Cox said:
Hi Jeff,

In ASP.NET syntax, the tilde (~) represents the root of the web.
Therefore, to get to the root and back down to the image folder, try this:

Server.MapPath("~/image/file.jpg")

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

Jeff said:
Hey

asp.net 2.0

The code below saves the "helloworld.jpeg" file to:
C:\Documents and Settings\Jeff\My Documents\Visual Studio
2005\WebSites\BN\webForms\Profile

HttpPostedFile file = fuPicture.PostedFile;
byte[] data = new byte[file.ContentLength];
file.InputStream.Read(data, 0, file.ContentLength);
Profile.Picture = data;
Profile.PictureType = file.ContentType;
//This is just a test:
System.IO.MemoryStream mstream = new System.IO.MemoryStream();
mstream.Write(data, 0, data.Length);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
bmp.Save(Server.MapPath("helloworld.jpeg"),
System.Drawing.Imaging.ImageFormat.Jpeg);
mstream.Close();

\webForms is a subfolder in my project
\webForms\Profile is the folder which contains the form which execute the
code above....

This works but this isn't good solution because it gives the physical
path to the file on my devbox and I'm not sure I can use this on a live
server...

How can I specify that for example the files generated should be saved to
"\image\" in my project folder (relative path)....??

I wonder because I want to save the path to the file in user's Profile
and are looking for the best way of specifying the path...

any suggestions?

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top