This documentation is archived and is not being maintained.

HtmlInputFile.Value Property

Gets the full path of the file on the client's computer.

[Visual Basic]
Overrides Public Property Value As String
[C#]
public override string Value {get; set;}
[C++]
public: __property String* get_Value();
public: __property void set_Value(String*);
[JScript]
public override function get Value() : String;
public override function set Value(String);

Property Value

The full path of the client's file.

Exceptions

Exception Type Condition
NotSupportedException An attempt is made to assign a value to this property.

Remarks

The Value property retrieves the full path of the file on the client's computer (for example "C:\MyFiles\Test.txt"). This is useful when you need to know where the file is stored on the computer submitting the file. This property is also commonly used to determine the original file name. To get the original file name, parse the value of this property.

Note   The Value property is read-only. If you attempt to assign a value to this property, a System.NotSupportedException is thrown.

Example

[Visual Basic, C#] This example demonstrates how to use the Value property to display the full path of the file on the client's computer. For this example to work properly, you need to create a directory called TEMP on your C: drive.

[Visual Basic] 

<%@ Page Language="VB" AutoEventWireup="True" %>

<html>

<head>

   <title>

      HtmlInputFile Example

   </title>

   <script runat="server">

      Public Sub Button1_Click(Source As object, e As EventArgs) 
 
         If Text1.Value = "" Then 
 
            Span1.InnerHtml = "Error: you must enter a file name"
            Return

         End If
 
         If Not (File1.PostedFile Is Nothing) Then 
         
            Try

               File1.PostedFile.SaveAs("c:\temp\" & Text1.Value)
               Span1.InnerHtml = "<b>" & File1.Value & "</b>" & _
                                 " uploaded successfully to <b>c:\temp\" & _
                                 Text1.Value & "</b> on the Web server"
      
            Catch exc As Exception
      
               Span1.InnerHtml = "Error saving file <b>c:\temp\" & _
                                 Text1.Value & "</b><br>" & exc.ToString()

            End Try

         End If

      End Sub

   </script>

</head>

<body>

   <form enctype="multipart/form-data" runat="server">
 
       Select File to Upload: 
       <input id="File1" 
              type="file" 
              runat="server">
 
       <p>
       Save as filename (no path): 
       <input id="Text1" 
              type="text" 
              runat="server">
 
       <p>
       <span id=Span1 
             style="font: 8pt verdana;" 
             runat="server" />
 
       <p>
       <input type=button 
              id="Button1" 
              value="Upload" 
              OnServerClick="Button1_Click" 
              runat="server">
 
    </form>

</body>

</html>


[C#] 

<%@ Page Language="C#" AutoEventWireup="True" %>

<html>

<head>

   <title>

      HtmlInputFile Example

   </title>

   <script runat="server">

      public void Button1_Click(object Source, EventArgs e) 
      {
 
         if (Text1.Value == "") 
         {
            Span1.InnerHtml = "Error: you must enter a file name";
            return;
         }
 
         if (File1.PostedFile != null) 
         {
            try
            {
               File1.PostedFile.SaveAs("c:\\temp\\" + Text1.Value);
               Span1.InnerHtml = "<b>" + File1.Value + "</b>" + 
                                 " uploaded successfully to <b>c:\\temp\\" + 
                                 Text1.Value + "</b> on the Web server";
            }
            catch (Exception exc) 
            {
               Span1.InnerHtml = "Error saving file <b>c:\\temp\\" + 
                                 Text1.Value + "</b><br>" + exc.ToString();
            }
         }
      }

   </script>

</head>

<body>

   <form enctype="multipart/form-data" runat="server">
 
       Select File to Upload: 
       <input id="File1" 
              type="file" 
              runat="server">
 
       <p>
       Save as filename (no path): 
       <input id="Text1" 
              type="text" 
              runat="server">
 
       <p>
       <span id=Span1 
             style="font: 8pt verdana;" 
             runat="server" />
 
       <p>
       <input type=button 
              id="Button1" 
              value="Upload" 
              OnServerClick="Button1_Click" 
              runat="server">
 
    </form>

</body>

</html>

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlInputFile Class | HtmlInputFile Members | System.Web.UI.HtmlControls Namespace | Value | PostedFile | System.NotSupportedException

Show: