469,903 Members | 2,218 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

How to select an image for display in aspx

Hi All,

Can anyone help me out with this one. I have a basic aspx page with an image placeholder on it. I want to be able to click a button on the page and have a dialog window appear where I can navigate the Client's PC and select a file (a JPG of GIF). I then want to change the image placeholder to display the selected image.

The problem I have is that I just can't work out how to browse the clients hard-disk. I have tried "
commonDialog1 = CreateObject("UserAccounts.CommonDialog")" and

"MyFolder = New System.Windows.Forms.FolderBrowserDialog"

but both give me a dialog window 'ghost' that is, the appear as a frame without any contents. The only way I know they are there is if I drag another application window over them. The screen tries to redraw them without any luck.

TIA,

Peter Wallington

Oct 31 '05 #1
2 1681
I would think you would have to use an html file upload input control. (You cannot create common dialog boxs on a web app). You should be able to grab the selected filename from it???

<INPUT id="File1" type="file" name="fileInput" runat="server">

pseduo code to upload a file, modify accordingly:

If Not File1.PostedFile Is Nothing AndAlso Not File1.PostedFile.FileName = String.Empty Then
Try

fileName = Server.MapPath("~\uploads\") & Path.GetFileName(File1.PostedFile.FileName.ToStrin g)

File1.PostedFile.SaveAs(fileName)

fileSize = CType(File1.PostedFile.InputStream.Length, Integer)
contentType = File1.PostedFile.ContentType()

Dim fs As FileStream = New FileStream(fileName, FileMode.Open, FileAccess.Read)

imagefile = New Byte(CType(fs.Length, Integer)) {}

fs.Read(imagefile, 0, CType(fs.Length, Integer))

fs.Close()

FileFound = True

Catch ex As System.IO.FileNotFoundException

Trace.Warn("file not found", ex.ToString)


Catch ex As Exception

Trace.Warn("upload", ex.ToString)

End Try
End If

HTH,
Greg

"Peter Wallington" <ne**@paradigm-it.com.au> wrote in message news:43***********************@per-qv1-newsreader-01.iinet.net.au...
Hi All,

Can anyone help me out with this one. I have a basic aspx page with an image placeholder on it. I want to be able to click a button on the page and have a dialog window appear where I can navigate the Client's PC and select a file (a JPG of GIF). I then want to change the image placeholder to display the selected image.

The problem I have is that I just can't work out how to browse the clients hard-disk. I have tried "
commonDialog1 = CreateObject("UserAccounts.CommonDialog")" and

"MyFolder = New System.Windows.Forms.FolderBrowserDialog"

but both give me a dialog window 'ghost' that is, the appear as a frame without any contents. The only way I know they are there is if I drag another application window over them. The screen tries to redraw them without any luck.

TIA,

Peter Wallington

Oct 31 '05 #2
You forgot one. <roll eyes>

microsoft.public.dotnet.framework.aspnet
"Greg Burns" <bl*******@newsgroups.nospam> wrote in message news:u1****************@TK2MSFTNGP09.phx.gbl...
I would think you would have to use an html file upload input control. (You cannot create common dialog boxs on a web app). You should be able to grab the selected filename from it???

<INPUT id="File1" type="file" name="fileInput" runat="server">

pseduo code to upload a file, modify accordingly:

If Not File1.PostedFile Is Nothing AndAlso Not File1.PostedFile.FileName = String.Empty Then
Try

fileName = Server.MapPath("~\uploads\") & Path.GetFileName(File1.PostedFile.FileName.ToStrin g)

File1.PostedFile.SaveAs(fileName)

fileSize = CType(File1.PostedFile.InputStream.Length, Integer)
contentType = File1.PostedFile.ContentType()

Dim fs As FileStream = New FileStream(fileName, FileMode.Open, FileAccess.Read)

imagefile = New Byte(CType(fs.Length, Integer)) {}

fs.Read(imagefile, 0, CType(fs.Length, Integer))

fs.Close()

FileFound = True

Catch ex As System.IO.FileNotFoundException

Trace.Warn("file not found", ex.ToString)


Catch ex As Exception

Trace.Warn("upload", ex.ToString)

End Try
End If

HTH,
Greg

"Peter Wallington" <ne**@paradigm-it.com.au> wrote in message news:43***********************@per-qv1-newsreader-01.iinet.net.au...
Hi All,

Can anyone help me out with this one. I have a basic aspx page with an image placeholder on it. I want to be able to click a button on the page and have a dialog window appear where I can navigate the Client's PC and select a file (a JPG of GIF). I then want to change the image placeholder to display the selected image.

The problem I have is that I just can't work out how to browse the clients hard-disk. I have tried "
commonDialog1 = CreateObject("UserAccounts.CommonDialog")" and

"MyFolder = New System.Windows.Forms.FolderBrowserDialog"

but both give me a dialog window 'ghost' that is, the appear as a frame without any contents. The only way I know they are there is if I drag another application window over them. The screen tries to redraw them without any luck.

TIA,

Peter Wallington

Oct 31 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Popoxinhxan | last post: by
reply views Thread by Satish Appasani | last post: by
1 post views Thread by Stephen | last post: by
2 posts views Thread by Peter Wallington | last post: by
4 posts views Thread by tshad | last post: by
4 posts views Thread by MikeB | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.