Topic - File Upload
Faculty Name : Saravana Kumar
Q: What is "Has File" property for a FileUpload control?
Answer:
The "Has File" property is a property which is used for checking whether the file is posted or not i.e selected or not.This property returns the value true if the file is posted i.e selected and this returns false if the file is not posted.
Reference:
http://www.dotnetfunda.com/interview/exam4193-what-is-has-file-property-for-a-fileupload-control-.aspx
http://forums.asp.net/t/1336476.aspx
Faculty Name : Majesh
Q. How to restrict size of file upload in asp.net
Answer:
File upload control allows maximum file size is 4MB for that reason if we upload file size larger than 4MB we will get error page like “the page cannot displayed” or “Maximum request length exceeded”. We can increase the size of uploaded file by setting some properties in web.config file like this
<system.web>
<httpRuntime executionTimeout="9999" maxRequestLength="2097151"/>
</system.web>
Here httpRuntime means
Configures ASP.NET HTTP runtime settings. This section can be declared at the
machine, site, application, and subdirectory levels.
executionTimeout means
Indicates the maximum number of seconds that a request is allowed to execute before
being automatically shut down by ASP.NET.
maxRequestLength means
Indicates the maximum file upload size supported by ASP.NET. This limit can be used to
prevent denial of service attacks caused by users posting large files to the server. The size
specified is in kilobytes. The default is 4096 KB (4 MB).
Faculty Name : Majesh
Q. Can we use http handlers to upload a file in asp.net?
Answer:
Yes , We can use http handlers to upload a file in asp.net. To perform file upload in ASP.NET,you need to know two classes: the System.Web.UI.HtmlControls.HtmlInputFile class and the system.Web.HttpPostedFile. The first class represents an HTML control that the user uses to
select a file on the client side and upload it. The latter represents the uploaded file itself, and an
instance of this class is obtained from the HtmlInputFile control.
Faculty Name : Majesh
Q. What is "Content Type" for a FileUpload contol?
Answer: This is a property which is used for checking the format of the posted file.
The formats can be
1) text/plain: It specifies a plain text file (.txt file).
2) text/xml: It specifies xml file.
3) application/word: It specifies a document file.
4) image/gif: It specifies a gif format image.
Like this we can mention the different dot extension properties.
Faculty Name : Majesh
Q) What are the properties and methods of FileUpload control
Answer:
FileUpload control properties :
Enabled : Enables you to disable the FileUpload control.
FileBytes : Enables you to get the uploaded file contents as a byte array.
FileContent : Enables you to get the uploaded file contents as a stream.
FileName : Enables you to get the name of the file uploaded.
HasFile : Returns True when a file has been uploaded.
PostedFile : Enables you to get the uploaded file wrapped in the HttpPostedFile
object.
FileUpload control methods:
Focus : Enables you to shift the form focus to the FileUpload control.
SaveAs : Enables you to save the uploaded file to the file system.
No comments:
Post a Comment