Does anyone know how to do FileUpload in asp.net 1.1. My current code works for 2.0 but I need to do this for 1.1. I know that FileUpload.HasFile doesn't work.Here is my code:

<%@ Page Language="vb" AutoEventWireup="false" Inherits="Promethius.PCMSPro.UploadFile" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script runat="server">  
  Protected Sub cmdUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs)   
        If Me.File1.PostedFile.ContentLength > "" Then
            Me.File1.PostedFile.SaveAs(Server.MapPath("~/Upload/" & Me.File1.PostedFile.FileName))
            Me.ltOne.Text = "File Uploaded Successfully"
        End If
  End Sub   
		<TITLE>Upload File</TITLE>
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<meta http-equiv="Content-Language" content="en-us">
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
	<body leftmargin="0" topmargin="0" bottommargin="0" rightmargin="0">
		<div id="global">
			<form enctype="multipart/form-data" runat="server">
				<table height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">
						<td id="TitleArea" class="dialogTitle">
							<table border="0" cellpadding="0" cellspacing="0" width="100%">
									<td class="dialogTitle" bgcolor="#ecf0f4">
										<img src="../images/icons/prom24.gif" align="left"><b><font face="Tahoma" color="#425971">Upload 
						<td id="mainCell" height="100%" valign="top">
							<font face="tahoma" size="1">&nbsp;</font>
							<div align="left" style="PADDING-LEFT:20px;PADDING-BOTTOM:20px;WIDTH:100%;PADDING-TOP:20px">
								<asp:Label id="lblMessage" runat="server"></asp:Label><BR>
								Select file to upload:<BR>
								<input id="File1" type="file" runat="server" NAME="File1" style="WIDTH: 328px; HEIGHT: 22px"
								File Location:
								<asp:DropDownList ID="FileLoc" Runat="server"></asp:DropDownList>
							<INPUT id="control" type="hidden" name="control" runat="server">
						<td class="dialogButtons">
							<table border="0" cellpadding="0" cellspacing="0">
									<td width="100%" bgcolor="#ecf0f4">&nbsp;</td>
									<td nowrap>
										<asp:Button ID="cmdUpload" Runat="server" Text="Upload Document" OnClick="cmdUpload_Click"></asp:Button>
										<input type="button" value="Done" class="Button" onclick="window.close();">
										<br />
										<asp:Literal ID="ltOne" runat="server" />  
7 Years
Discussion Span
Last Post by nandux8

ummmm i think i can solve your problem following is the code
try it

<%-- The Web Form with the EncType property set to Multipart/Form-Data --%>
<form Method="Post" EncType="Multipart/Form-Data" RunAt="Server">

   <%-- The File upload Html control --%>
   Choose Your File  To Upload <BR>
   <Input ID="MyFile" Type="File" RunAt="Server">

   <%-- A button - when clicked the form is submitted and the
            Upload_Click event handler is fired... --%>
   <Input Type="Submit" Value="Upload" 
             OnServerClick="Upload_Click" RunAt="Server">


The different attributes of HtmlInputFile control could be as follows:

   ID="Specify an ID"
   Accept="Specify MIMEencodings"
   MaxLength="Specify maximum length of file path"
   Size="Specify width of textbox of the control" >

   Sub Upload_Click(Sender as Object, e as EventArgs)

  ' Display properties of the uploaded file
  FileName.InnerHtml = MyFile.PostedFile.FileName
  FileContent.InnerHtml = MyFile.PostedFile.ContentType 
  FileSize.InnerHtml = MyFile.PostedFile.ContentLength
  UploadDetails.visible = True

  'Grab the file name from its fully qualified path at client 
  Dim strFileName as string = MyFile.PostedFile.FileName
  ' only the attched file name not its path
  Dim c as string = System.IO.Path.GetFileName(strFileName)

  'Save uploaded file to server at C:\ServerFolder\
    MyFile.PostedFile.SaveAs("C:\ServerFolder\" + c)
    Span1.InnerHtml = "Your File Uploaded Sucessfully at server as: " & _
                      "C:\ServerFolder\" & c
  Catch Exp as exception
    Span1.InnerHtml = "An Error occured. Please check the attached  file"
    UploadDetails.visible = false
  End Try
End Sub

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.