0

I am creating a small application where i am reading am image from the database, storing the image in a file, and then setting the Image Control ImageURL property to the created file

The code is pretty straight forward

Dim m_Bytes As Byte() = DirectCast(command.ExecuteScalar, Byte())

    Dim strfn As String = "D:\" + Convert.ToString(DateTime.Now.ToFileTime()) + ".jpeg"

    Dim fs As New FileStream(strfn, FileMode.CreateNew, FileAccess.Write)

    fs.Write(m_Bytes, 0, m_Bytes.Length)
    fs.Flush()
    fs.Close()

    Image1.ImageUrl = strfn

The image is getting created properly at the location but the image control does not render an image . I checked the source of the page and the image control was pointing to

 <img id="Image1" src="D:\129901061171254403.jpeg" />

The src is pointing to the correct location...

Thanks in Advance....

2
  • 1
    D:\ is a strange location. I don't expect IIS will serve files from there. It needs to go under your wwwroot folder at least. Commented Aug 22, 2012 at 11:12
  • The path needs to be within your website. Id recommend creating a directory from your site root perhaps something like /GeneratedImages/ and generating your images in that location then your image control ImageUrl property should point to that location and be servered by the webserver. You can't specify windows file paths as sources for images (D:\whatever) all paths have to be relative to your website root directory. Commented Aug 22, 2012 at 11:14

1 Answer 1

1

You must store the image in a location that is accessible under IIS.

You could for instance have a folder under you application where you store the image. Let's say your application is deployed in the folder d:\virtualDirs\myApp and you browse it on the url http://someserver.com/superapp/.

You could then store the image in (for instance) the folder d:\virtualDirs\myApp\dynImages:

d:\virtualDirs\myApp\dynImages\129901061171254403.jpeg

and then set the ImageUrl:

Image1.ImageUrl = "~/dynImages/129901061171254403.jpeg";

Sending the local folder path in the webpage simply wont work since that is where the file is on the server.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.