File uploading - Get file size?


How do i get the file size when a user uploads a file? i can now get the filename and it uploads the file to my server correctly, but i'm unable to get the file size of the file...
These are the codes i used...

fn = System.IO.Path.GetFileName(FileField.PostedFile.FileName)
fs = FileField.PostedFile.ContentLength

Even these set of codes also won't work...

fn = System.IO.Path.GetFileName(FileField.PostedFile.FileName)
fs = System.IO.Path.GetFileName(FileField.PostedFile.ContentLength)

The error that i get when i added the 2nd line of code to get the file size is:
Object must implement IConvertible.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Object must implement IConvertible.

Anyone knows whats wrong? it works fine when i only use the 1st line of code... but once i add in the 2nd line to get the filesize... it cant work anymore... pls help!
3/27/2004 1:13:54 PM 91979 articles. 4 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 47
Get it on Google Play
Get it on Apple App Store

what have you declared fs as int or string, I am guessing string

// this will fail
string fs = "";
fs = FileField.PostedFile.ContentLength;
// this should work ?
string fs = "";
fs = FileField.PostedFile.ContentLength.ToString();
// or this ?
int fs = 0;
fs = FileField.PostedFile.ContentLength;

3/27/2004 3:00:06 PM
thanks for replying... i solved it... turned out to be a typo error in my function... thanks!
3/27/2004 6:09:41 PM

Similar Artilces:

Problem in Upload file size validation(file upload tool)
I am using an asp file upload tool. The maximum size of the uploaded file should be 10 MB. I had written validation in the codebehind for showing a message box(javascript). But in the web.config file the MaxRequestLength is given as 10 MB. so when the user tries to upload a file with size greater than the maximum file size, the control is going to the one page(page cannot be displayed). So for showing the user an error message, what can be done other than incresing the MaxRequestLength ..?? Hello, This is common issue with file size restriction. It happens because the browser can'...

How much size of file can be uploaded with file upload control
How much size of file can be uploaded with file upload control? By default its 4mb but it can be chaged through web config settingsAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved. For a detailed explanation on your query have a look into this article Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point...

File Upload File size error
Hello All, Whenever I try to upload a file bigger than 4MB I get an "Internet Explorer cannot display the webpage" error. Then I override OnError and tried to display some friendly message using Response.write, but still get "cannot display the webpage" error and not my custom message. How can I completely override the default behavior on this.  Please help me to solve this issue...   Thanks in Advance.--Vidya-- Not sure why you're getting that particular error, as you would get a Max Request Lenght Exceeded error if you attempt to request upl...

Check file size as the file is being uploaded !
Is it possible to check the file size of a file while it is being uploaded?  I would like to check the file size during the upload before it is Refer to the following thread. My Blog MARK this post as ANSWERED, if you find it helpful) Thanks I've tried the code it works but I have a few questions. The content length returned which you check against is the length of the entire request. If I'm uploading a file and sending other data from some text boxes with it, how will ...

file uploader save file on server and in database and upload this file on client
hi,i have a file uploader control user can attach files (.rar, .zip, etc) and store file folder and path in database. and another user can click of attach link and can download that file. how can i do this please solve out this problem. you can find your problem solution in this link and you can store the file name in your database server. Mark as Answred If This Blog has Helped You.RegardsMitesh Darjihttp://www.indianic.com As always there are many ways and which ...

To increase file size upload option of a html file upload control in 1.1
Hi, whenever i try uploading files greater than 15kb or so, my file control fails. But smaller files are easily uploaded. Please helpIf you keep your feet firmly on the ground, you'll have trouble putting on your pants! Hi, the default maximum upload size of the total form data, so not only your fileupload, is limited to 4Mb. You can increase that number by overriding the default settings in the web.config. Alter the <httpRuntime maxRequestLength="" /> attribute. Dealing with the maximum upload size of ASP.NET. Grz, Kris.Read my blog. Handy Firefox plugins for web ...

File Upload Problem
Hi Everyone,I was grateful to be able to download the code for uploading files into a folder from Sreedhar's web page. The code works well, but whenever there is another new file with the same file name being uploaded into the destination folder, the old file will be replaced. I am wondering if there is any way to solve this problem (How about adding a number to the new file's name, e.g. File1.doc, if there is an existing File.doc?) I am an absolute beginner and any help is deeply appreciated.The original code is as follows: <%@ Page Language="VB" MasterPageFile="~/MasterP...

File Upload control-Control file size
I am using a file upload tool. I believe the default permissible size for a file uploaded through this tool is around 4 mb. How do I change this limit? I don't want it to be changed for all upload controls on the page. I just want it to be changed for one particular control which uploads music. I want to raise the uploaded file size limit for music to 10MB. hi, here are some information for you to refer to,

File Upload Control ... file size problems
I am using a fileupload control, is there anyway i can determine the file size of attached file before it gets posted to the server ..... iam not particularly happy with the user having to wait until file is posted to the server before i can determine size of file uploaded.... I have increased the file upload limit to approx 10 mb in the web.config file ,  <httpRuntime maxRequestLength="11000"  enable = "True" requestLengthDiskThreshold="512" useFullyQualifiedRedirectUrl="True" executionTimeout="120" />  and have code to capture the size in code behind file Sub Sav...

upload file by file
hi all,   we have project, local in server, more then one people do the update, let's say, if all file local in test, I did the modify in local and build and upload the whole test file into service, it work fine. but if I only upload helloone.aspx. and its Vb file (under test) into service, it did not work( the VB code) , is that a way to only upload file by file to service, thank you   If I understand your problem correctly, I think the problem that you may be having is that after pages are compiled locally they are not being compiled for the entire site.  I would su...

Posting filepath in file upload control in .NET to the next page and uploading the file from second page
In our application (using C# .NET) there is a form with file upload options. After filling up the form details, the summary of the details need to be shown in the next page before committing the information into the database. Right now, Server.Control is used to transfer the contents to the next page and the form details are retrieved using Request.Form["control id"]. But this is not working for File upload control alone.File upload can not be done in the first page itself, as the foreign key in File upload table gets updated only in second page after confirmation. Therefore, is th...

How to identify the original file type and restrict the file uploading while using file upload control
 Hi , I am uploading a file using FileUpload control in using wrote the code to upload only PDF files. the user can change the extension and change to PDF . I have to check is the file original PDF or not then i have to upload the PDF files only . How to do this ??  Hi, Check the file Mime type for "application/pdf" by looking at the:  FileUpload1.PostedFile.ContentType RegardsSmcoxonNo Gem is ever polished without some friction. Hi smcoxon , Thanks For Replying ,But i found that there is no use using PostedFil...

How to avoid the blank page if the size the uploaded file is larger than the size allowed by .Net?
If I tried to upload a file larger than that allowed by .Net, a blank page appeared. I don't want to adjust the max request size in the config file. Is there any way to direct the user to another page or show a friendly page?  I am using vs2008 with sp1. Please try your answer first and make sure it works before you give it me.  I searched on google a lot and painfully. But no solution found. Thanks for your reading and replying. Gary    Thanks for reading and replying my answer. Try this article:

File Upload Problem for a File Size more than 4 MB
Hi All, I am trying to upload a file from the client machine to my Application Server. It seems to work fine when I Upload a file less than 4 MB. Anything above 4MB gives me the Error. Does somebody knows the limit for the File Uplaods and workarounds if possbile?. Any kinda hep would be appreciated. Thanks, Anmol maxRequestLength can be set to allow larger files, in HttpRuntime in Web.Config or Machine.ConfigStarting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Blog Have a look at UPLOADING FILES WITH XMLHTTP - it performs much better than Http POST. Thank...

How can I control the size of a file when the file is upload to the server?
Hello! I am wondering how I can control the size of a file that the client load up to the server? I am working in C#. Sincerely, Albert Hi Albert, By control do you mean restrict the size of the upload? One way to do this would be to override the maximum request length with an entry in web.config, for example, the following would set the maximum length to 8 MB. <httpRuntime maxRequestLength="8192" /> The default is 4MB. HTH,Scott

Web resources about - File uploading - Get file size? -

Uploading and downloading - Wikipedia, the free encyclopedia
Examples of a remote system from which a download might be performed include a web server , FTP server, email server, or other similar systems. ...

Facebook Lets You Tag Photos While They're Uploading
Facebook now lets you add tags to photos before they're finished uploading.

Facebook for iPhone 3.0 to Include Video Uploading for 3GS Owners
We’ve heard a lot of people say the iPhone’s built-in support for YouTube video uploading is going to make a huge impact on the number of people ...

Defence bureaucrat pleads guilty to uploading secret document online
... embarrassing security breach with &quot;Five Eyes&quot; intelligence document. A former junior Defence bureaucrat has pleaded guilty to uploading ...

Uploading Bautista bat flip GIFs could get you sued under TPP, copyright activists warn
Copyright activists say Canadians could face lawsuits, fines or worse for ripping the latest Justin Bieber CD or uploading an animated GIF of ...

Xiaomi apologizes for uploading address book data from smartphones without permission
Former Android head and Xiaomi VP Hugo Barra has apologized to owners of its smartphones for "any concern caused" by collecting contact data ...

Senator calls for FTC investigation of Apple and Google over stealth photo uploading capabilities
Is this how we’ll have to open apps in the future? When we broke the news that iOS (and later Android) apps could upload your photo library (along ...

YouTubers Now Uploading Over 35 Hours Of Video Per Minute!
This week YouTube's got some big news! YouTubers are now uploading over 35 hours of video per minute, up from 24 hours a minute in March.

Google Play Books updated with new design, PDF and EPUB uploading
Caught up in all of the hullabaloo around the keynote, Google Play Books received a notable update in the Play Store to not only bring new UI ...

Twitter rolling out group messaging, 30-second video uploading
Fast Company Twitter rolling out group messaging, 30-second video uploading Android Community Different social networks are doing everything ...

Resources last updated: 12/8/2015 9:11:00 AM