Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

How to read the image file from file system (using URL) within aspx.cs?

I need to process the image during the postback. The image file is stored on the website (URL path). However, when I coded the path in URL, the compiler complains. However, I really cannot specify the absolute file path in the file system. You just don't klnow where is the file (web farming).
How do I resolve this delima?
0
chuang4630
Asked:
chuang4630
  • 2
  • 2
1 Solution
 
YZlatCommented:
what error are you getting?
0
 
chuang4630Author Commented:
URI formats are not supported

code:
string WorkingDirectory = "http://localhost/MySite/images/site";
System.Drawing.Image imgPhoto = System.Drawing.Image.FromFile(WorkingDirectory + "/DefaultBkg.jpg");

0
 
YZlatCommented:
try

C:\Inetpub\wwwroot\MySite\images\site

instead of

http://localhost/MySite/images/site
0
 
chuang4630Author Commented:
I know you can always use the file system path. But in the production environment, how do you know the absolute file system path?
0
 
deanvanrooyenCommented:
       // url http:/mysite.com/images/page.aspx?image=pic.jpg
       string image =  Request.QueryString["image"];
       string path = Server.MapPath(" ~/images/" + image);

       System.Drawing.Image im = System.Drawing.Image.FromFile(path);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now