473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

I need a Server.MapPath advice

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
Jul 2 '06 #1
2 1565
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" <it************@hotmail.com.NOSPAMwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
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

Jul 3 '06 #2
Thanks, it works great...
"Ken Cox [Microsoft MVP]" <BA**********@newsgroups.nospamwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
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" <it************@hotmail.com.NOSPAMwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>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


Jul 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: John Rebbeck | last post by:
I've got the directory f:\Company\Product set as web shared so it's got a virtual directory in the default web site on my test server's IIS. If I try to use Server.MapPath in that site it returns a...
4
by: Laphan | last post by:
Hi All Sorry to be irate, but the whole concept of Server.MapPaths really has me in a tiswas!! In order to confirm once and for all, could you please advise me on the following: 1) There...
7
by: Roshawn Dawson | last post by:
Hi, I have an xslt file located in the root directory. It is used by an aspx pages in both the root directory and a subdirectory. But for some strange reason, the aspx page in the subdirectory...
5
by: manmit.walia | last post by:
Hello All, I am stuck on a conversion problem. I am trying to convert my application which is written in VB.NET to C# because the project I am working on currently is being written in C#. I tried...
2
by: WB | last post by:
Hi, How can I access Server and Trace within a helper class? I have a webform that allows user to select a PDF file (on the web server) and render a jpeg image of that PDF file. The helper...
7
by: benoit | last post by:
Hi, if I write this code to retrieve a folder on the server Server.mappath("/DATA") I get this error message System.InvalidOperationException: Failed to map the path '/DATA' the virtual...
11
by: brett | last post by:
I use two test servers and one production. I have a Utilities class that holds many of the links used through the site. One of the variables in this class is assigned the domain name. I need to...
4
by: vunet.us | last post by:
How to use server.mappath() parent folder correctly: Server.MapPath("../test.asp") Thank you for the hint.
3
by: rn5a | last post by:
Server.MapPath returns the physical file path that corresponds to the specified virtual path whereas Request.MapPath maps the specified virtual path to a physical path. Assuming that a file named...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.