Groups | Blog | Home
all groups > dotnet faqs > october 2005 >

dotnet faqs : How to select an image for display in aspx


Peter Wallington
10/31/2005 12:00:00 AM
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 =3D CreateObject("UserAccounts.CommonDialog")" and=20

"MyFolder =3D New System.Windows.Forms.FolderBrowserDialog"=20

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,

Greg Burns
10/31/2005 4:51:22 PM
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=3D"File1" type=3D"file" name=3D"fileInput" runat=3D"server">

pseduo code to upload a file, modify accordingly:

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

fileName =3D Server.MapPath("~\uploads\") & =
Path.GetFileName(File1.PostedFile.FileName.ToString)

File1.PostedFile.SaveAs(fileName)

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

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

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

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

fs.Close()

FileFound =3D True

Catch ex As System.IO.FileNotFoundException

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

Catch ex As Exception

Trace.Warn("upload", ex.ToString)
=20
End Try
End If

HTH,
Greg

[quoted text, click to view]
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 "=20
commonDialog1 =3D CreateObject("UserAccounts.CommonDialog")" and=20

"MyFolder =3D New System.Windows.Forms.FolderBrowserDialog"=20

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,

Greg Burns
10/31/2005 5:27:10 PM
You forgot one. <roll eyes>

microsoft.public.dotnet.framework.aspnet
[quoted text, click to view]
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=3D"File1" type=3D"file" name=3D"fileInput" runat=3D"server">

pseduo code to upload a file, modify accordingly:

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

fileName =3D Server.MapPath("~\uploads\") & =
Path.GetFileName(File1.PostedFile.FileName.ToString)

File1.PostedFile.SaveAs(fileName)

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

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

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

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

fs.Close()

FileFound =3D True

Catch ex As System.IO.FileNotFoundException

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

Catch ex As Exception

Trace.Warn("upload", ex.ToString)
=20
End Try
End If

HTH,
Greg

[quoted text, click to view]
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 "=20
commonDialog1 =3D CreateObject("UserAccounts.CommonDialog")" and=20

"MyFolder =3D New System.Windows.Forms.FolderBrowserDialog"=20

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,

AddThis Social Bookmark Button