Asp.net uses the file control to upload files and determine the file size. When the file path is obtained, an error [system. Io. filenotfoundexception: file not found] is returned.

Source: Internet
Author: User

When Asp.net uploads a file and uses the file control of the HTML control, the following error occurs: [system. Io. filenotfoundexception: the file cannot be found]. This is why the full path name cannot be obtained during file upload.

When a file is uploaded using a file stream to obtain the absolute path of the File Uploaded by the client, an error is reported sometimes because the security settings are different in different browsers.

In IE7/8/FF/GG, the uploaded file does not display the full path, GG and FF only display the file name, and IE8 displays c: \ fakepath \ test.txt ". This is because of browser security settings.

 

Solution:

Open IE browser --> Internet Options --> Security --> Custom Level --> others --> enable "show file directory path when uploading files to the server"

Click OK and then run again.

 

Another solution:

If the error message is about the file size you readCode, That is the same as what I met, the following code:

Httpfilecollection _ FILES = system. Web. httpcontext. Current. Request. files;

String name = _ FILES [I]. filename;

Fileinfo Fi = new fileinfo (name );

Then: fi. length gets the file size to determine the upload size limit.

In this case, an error is reported, that is, the path problem mentioned above.

In this case, convert the file size to _ FILES [I]. contentlength, and then OK.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.