ToolBox HTML Control HTMLFile

HTML File Web Server Control

In ASP.NET environment,This article describes you how to work with HTML File Control.In HTML environment, File is an object that represents a FileUpload in an HTML form. The FileUpload control in a HTML form contains all instance of an <input type="file"> tag.

The HtmlInputFile control can be used to uploading binary or text files from a browser client to the server. which was implemented and works with Microsoft Internet Explorer version 3.02 or Higher. HtmlInputFile controls requires the full path of the uploading file.for example ,"d:\Photos\img1.jpg" in the text box of the control.

There are several functions available to access the HTML File.some of its funtions are as follows,

  • document.getElementById()
  • document.getElementByName()
File Objects Properties
  • id -Sets or returns the id of a File
  • form -Returns a reference to the form that contains the File
  • accessKey -Sets or returns the keyboard key to access a File
  • alt -Sets or returns an alternate text to display if a browser does not support Files
  • disabled -Sets or returns whether or not a File should be disabled
  • tabIndex -Sets or returns the tab order for a File
  • name -Sets or returns the name of a File
  • type -Returns the type of form element a File is
  • defaultvalue - Sets or returns the initial value of the FileUpload object
  • value -Sets or returns the text that is displayed on the File
  • title -Sets or returns an element's advisory title
  • lang -Sets or returns the language code for an element
  • dir -Sets or returns the direction of text
  • className -Sets or returns the class attribute of an element
File Objects Methods
  • blur() -Performs focus when leave from the control
  • click() -Simulates a mouse-click on a File
  • focus() -Performs focus when enter into the control

The following code snippets explains you the HTML File in the web form.

in .aspx.cs page,

void btn1_Click(object Source, EventArgs e)
  {

    if (txt1.Value == "")
    {
      Span1.InnerHtml = "file name required";
      return;
    }

    if (File1.PostedFile.ContentLength > 0)
    {
      try
      {
        File1.PostedFile.SaveAs("d:\\apppath\\" + txt1.Value);
        Span1.InnerHtml = "File uploaded successfully to c:\\temp\\"
         + txt1.Value + " on the Web server.";
      }
      catch (Exception ex)
      {
        Span1.InnerHtml = "Error saving file d:\\apppath\\" + txt1.Value + "
" + ex.ToString() + "."; } } }

in .aspx page,

<body> 
    <h3>Example</h3>
     <form id="Form2" enctype="multipart/form-data" 
          runat="server">
       Select File to Upload: 
       <input id="File1" 
              type="file" 
              runat="server">
      <p>
       <input id="txt1" 
              type="text" 
              runat="server">
       </p>
       <p>
       <span id=Span1 
             style="font: 8pt verdana;" 
             runat="server" />
       </p>
       <p>
       <input type=button 
              id="btn1" 
              value="Upload" 
              onserverclick="btn1_Click" 
             runat="server">
       </p>
   </form>
 </body>
 
Related Links

Posted by: Admin
Posted on: 9/18/2009 at 4:50 PM
Tags: , , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (7) | Post RSSRSS comment feed

Comments

Onlineatoz.net

Friday, September 18, 2009 4:51 PM

trackback

ToolBox HTML Control HTMLHidden

ToolBox HTML Control HTMLHidden

computers keyboard United States

Thursday, April 22, 2010 4:26 PM

computers keyboard

Thanks for the great post. It reminds me that I have to bring more structure in to my blogging. Your blog is very interesting. Please let me know how to go for your rss blog.

ugg boots People's Republic of China

Saturday, June 26, 2010 4:05 AM

ugg boots

Well , the view of the passage is totally correct ,your details is really  reasonable and  you <a href=" http://www.discountbootsonsale.co.uk/
" >wslmart.net </a> guy give us  valuable  informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum!

wholesale replica rolex watches People's Republic of China

Tuesday, June 29, 2010 8:48 AM

wholesale replica rolex watches

I am SO attracted to palm trees!

Thanks for the interesting facts too!

herve leger dress People's Republic of China

Tuesday, June 29, 2010 8:49 AM

herve leger dress

Although I can't agree with all you staded, I must confess I do love your way of writing.

alexander wang boots discount People's Republic of China

Monday, July 19, 2010 10:45 AM

alexander wang boots discount

vdfzb erha shy

nfl jersey People's Republic of China

Friday, July 23, 2010 9:09 AM

nfl jersey

Thanks for the info!!

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading