Upload file through ASP.net

<% @Page Language="C#" %>
<html>
<head>
  <title>File upload in ASP.NET</title>
</head>
<body bgcolor="#ffffff" style="font:8pt verdana;">
<script language="C#" runat="server">
void btnUploadTheFile_Click(object Source, EventArgs evArgs) 
{
  string strFileNameOnServer = txtServername.Value;
  string strBaseLocation = 

"c:\\Inetpub\\vhosts\\domain.com\\httpdocs\\test2\\";
  
  if ("" == strFileNameOnServer) 
  {
    txtOutput.InnerHtml = "Error - a file name must be specified.";
    return;
  }

  if (null != uplTheFile.PostedFile) 
  {
    try 
    {
      

uplTheFile.PostedFile.SaveAs(strBaseLocation+strFileNameOnServer);
      txtOutput.InnerHtml = "File <b>" + 
        strBaseLocation+strFileNameOnServer+"</b> uploaded 

successfully";
    }
    catch (Exception e) 
    {
      txtOutput.InnerHtml = "Error saving <b>" + 
        strBaseLocation+strFileNameOnServer+"</b><br>"+ e.ToString();
    }
  }
}
</script>

<table>
<form enctype="multipart/form-data" runat="server">
<tr>
  <td>Select file:</td>
  <td><input id="uplTheFile" type=file runat="server"></td>
</tr>
<tr>
  <td>Name on server:</td>
  <td><input id="txtServername" type="text" runat="server"></td>
</tr>
<tr>
  <td colspan="2">
  <input type=button id="btnUploadTheFile" value="Upload" 
                    OnServerClick="btnUploadTheFile_Click" 

runat="server">
  </td>
</tr>
</form>
</table>
    
<span id=txtOutput style="font: 8pt verdana;" runat="server" />

</body>
</html>


 
  • 0 Корисниците го најдоа ова како корисно
Дали Ви помогна овој одговор?

Понудени резултати

How do I setup customized Apache Handlers?

What are Apache Handlers? Apache handlers allow you to control what Apache will do with certain...

How do I customize my web site's Error Pages?

Overview With this tool you can create custom error pages to display when a user enters a wrong...

How do I create custom MIME Types?

Overview MIME Types tell browsers how to handle specific file extensions. For example, the...

How do I create a backup of my web site, directory or hosting account?

Overview Backups allow you to download (to your computer) a zipped copy of either you entire...

How do I view how much bandwidth my web site has used today, this month, or this year?

Overview The Bandwidth Usage feature allows you to see the bandwidth usage for your site. It...

Powered by WHMCompleteSolution