473,421 Members | 1,618 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,421 software developers and data experts.

HtmlInputFile and property's

I'm uploading files to a location on my server. It works fine accept, I can't
seem to get the control over the max file size to upload and the types I want
to only allow.
Max file size = 50KB
Types = .gif and .jpg

I've tried using the accept property but it doesn't work, the dialog opens
asking for *.* all files and allows them to be uploaded. And I can't restrict
file size?

Is there a way to set this in the code-behind routine via the HtmlInputFile
properties?

i.e.
<input id="inpFileUp" Type="file" Accept="image/gif" runat="server" />

I'm using the MS routine that works pretty well, found on their article:

Protected WithEvents inpFileUp As HtmlInputFile

If Not inpFileUp.PostedFile Is Nothing And
inpFileUp.PostedFile.ContentLength > 0 Then

Dim fn As String =
System.IO.Path.GetFileName(inpFileUp.PostedFile.Fi leName)
Dim SaveLocation As String
SaveLocation = Server.MapPath("\xxxx\xxxxxxx\" & fn)
Try
inpFileUp.PostedFile.SaveAs(SaveLocation)
Response.Write("The file has been uploaded.")
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload.")
End If

Thanx a bunch.
Nov 19 '05 #1
4 1452
Hi Chris,

An HtmlInputFile renders an "input type='file'" HTML element on the client.
There is no way to know what the file size is until it is uploaded. The only
data in the HTML element is the path to the file on the client machine. All
you can do is either accept or reject the file after uploading. You CAN
restrict file types by checking the file extension in the "value" property
of the input object on the client, since the full path including the file
extension is in the box. Other than that...

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
I'm uploading files to a location on my server. It works fine accept, I
can't
seem to get the control over the max file size to upload and the types I
want
to only allow.
Max file size = 50KB
Types = .gif and .jpg

I've tried using the accept property but it doesn't work, the dialog opens
asking for *.* all files and allows them to be uploaded. And I can't
restrict
file size?

Is there a way to set this in the code-behind routine via the
HtmlInputFile
properties?

i.e.
<input id="inpFileUp" Type="file" Accept="image/gif" runat="server" />

I'm using the MS routine that works pretty well, found on their article:

Protected WithEvents inpFileUp As HtmlInputFile

If Not inpFileUp.PostedFile Is Nothing And
inpFileUp.PostedFile.ContentLength > 0 Then

Dim fn As String =
System.IO.Path.GetFileName(inpFileUp.PostedFile.Fi leName)
Dim SaveLocation As String
SaveLocation = Server.MapPath("\xxxx\xxxxxxx\" & fn)
Try
inpFileUp.PostedFile.SaveAs(SaveLocation)
Response.Write("The file has been uploaded.")
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload.")
End If

Thanx a bunch.

Nov 19 '05 #2
IE hasn't implemented the Accept feature. you control the max upload size in
the web config (maxRequestLength). note: if the user tries to upload a
larger file, you can not detect and give an error, the upload is stopped by
closing the connection. the browser generally reports a page not found
error.

-- bruce (sqlwork.com)

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
| I'm uploading files to a location on my server. It works fine accept, I
can't
| seem to get the control over the max file size to upload and the types I
want
| to only allow.
| Max file size = 50KB
| Types = .gif and .jpg
|
| I've tried using the accept property but it doesn't work, the dialog opens
| asking for *.* all files and allows them to be uploaded. And I can't
restrict
| file size?
|
| Is there a way to set this in the code-behind routine via the
HtmlInputFile
| properties?
|
| i.e.
| <input id="inpFileUp" Type="file" Accept="image/gif" runat="server" />
|
| I'm using the MS routine that works pretty well, found on their article:
|
| Protected WithEvents inpFileUp As HtmlInputFile
|
| If Not inpFileUp.PostedFile Is Nothing And
| inpFileUp.PostedFile.ContentLength > 0 Then
|
| Dim fn As String =
| System.IO.Path.GetFileName(inpFileUp.PostedFile.Fi leName)
| Dim SaveLocation As String
| SaveLocation = Server.MapPath("\xxxx\xxxxxxx\" & fn)
| Try
| inpFileUp.PostedFile.SaveAs(SaveLocation)
| Response.Write("The file has been uploaded.")
| Catch Exc As Exception
| Response.Write("Error: " & Exc.Message)
| End Try
| Else
| Response.Write("Please select a file to upload.")
| End If
|
| Thanx a bunch.
|
|
Nov 19 '05 #3
how do you check/limit the extension then?
It states using Accept="image/gif" but that doesn't seem to work. I was sure
that the dialog box limits the types it will allow "browsing" for in addition.

"Kevin Spencer" wrote:
Hi Chris,

An HtmlInputFile renders an "input type='file'" HTML element on the client.
There is no way to know what the file size is until it is uploaded. The only
data in the HTML element is the path to the file on the client machine. All
you can do is either accept or reject the file after uploading. You CAN
restrict file types by checking the file extension in the "value" property
of the input object on the client, since the full path including the file
extension is in the box. Other than that...

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
I'm uploading files to a location on my server. It works fine accept, I
can't
seem to get the control over the max file size to upload and the types I
want
to only allow.
Max file size = 50KB
Types = .gif and .jpg

I've tried using the accept property but it doesn't work, the dialog opens
asking for *.* all files and allows them to be uploaded. And I can't
restrict
file size?

Is there a way to set this in the code-behind routine via the
HtmlInputFile
properties?

i.e.
<input id="inpFileUp" Type="file" Accept="image/gif" runat="server" />

I'm using the MS routine that works pretty well, found on their article:

Protected WithEvents inpFileUp As HtmlInputFile

If Not inpFileUp.PostedFile Is Nothing And
inpFileUp.PostedFile.ContentLength > 0 Then

Dim fn As String =
System.IO.Path.GetFileName(inpFileUp.PostedFile.Fi leName)
Dim SaveLocation As String
SaveLocation = Server.MapPath("\xxxx\xxxxxxx\" & fn)
Try
inpFileUp.PostedFile.SaveAs(SaveLocation)
Response.Write("The file has been uploaded.")
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload.")
End If

Thanx a bunch.


Nov 19 '05 #4
> how do you check/limit the extension then?

Using JavaScript, check the string in the "value" property of the input.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com...
how do you check/limit the extension then?
It states using Accept="image/gif" but that doesn't seem to work. I was
sure
that the dialog box limits the types it will allow "browsing" for in
addition.

"Kevin Spencer" wrote:
Hi Chris,

An HtmlInputFile renders an "input type='file'" HTML element on the
client.
There is no way to know what the file size is until it is uploaded. The
only
data in the HTML element is the path to the file on the client machine.
All
you can do is either accept or reject the file after uploading. You CAN
restrict file types by checking the file extension in the "value"
property
of the input object on the client, since the full path including the file
extension is in the box. Other than that...

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
> I'm uploading files to a location on my server. It works fine accept, I
> can't
> seem to get the control over the max file size to upload and the types
> I
> want
> to only allow.
> Max file size = 50KB
> Types = .gif and .jpg
>
> I've tried using the accept property but it doesn't work, the dialog
> opens
> asking for *.* all files and allows them to be uploaded. And I can't
> restrict
> file size?
>
> Is there a way to set this in the code-behind routine via the
> HtmlInputFile
> properties?
>
> i.e.
> <input id="inpFileUp" Type="file" Accept="image/gif" runat="server" />
>
> I'm using the MS routine that works pretty well, found on their
> article:
>
> Protected WithEvents inpFileUp As HtmlInputFile
>
> If Not inpFileUp.PostedFile Is Nothing And
> inpFileUp.PostedFile.ContentLength > 0 Then
>
> Dim fn As String =
> System.IO.Path.GetFileName(inpFileUp.PostedFile.Fi leName)
> Dim SaveLocation As String
> SaveLocation = Server.MapPath("\xxxx\xxxxxxx\" & fn)
> Try
> inpFileUp.PostedFile.SaveAs(SaveLocation)
> Response.Write("The file has been uploaded.")
> Catch Exc As Exception
> Response.Write("Error: " & Exc.Message)
> End Try
> Else
> Response.Write("Please select a file to upload.")
> End If
>
> Thanx a bunch.
>
>


Nov 19 '05 #5

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

Similar topics

5
by: shimonsim | last post by:
Hi, I need to upload pictures from client machine and I am using HtmlInputFile control I set validator to make sure that file has correct expention but if one of the files has incorrect extention...
9
by: Rob Meade | last post by:
Hi all, I've got some code here that builds a page dynamically, ie, added a table, rows, cells, controls in the cells and so on... Everything has gone fine until now, I need to add a 'File...
3
by: UJ | last post by:
Guys, I know this isn't the appropriate place to post this because it's HTML not ASP.Net but I need some guidance. I have a web page with an HTMLInputFile on it. The person enters the stuff,...
7
by: Buddy Ackerman | last post by:
I created this class Public Class HTMLFileInput : Inherits System.Web.UI.HtmlControls.HtmlInputFile Public Property Data As String Get Return ViewState("HTMLFileInput.Data") End Get Set...
7
by: cindy | last post by:
I have a System.Web.UI.HtmlControls.HtmlInputFile control that I use to submit files. Before the file is successfully submitted I validate another field on the form, it is the description of the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.