race2
02-07-2002, 18:36
Ho scaricato questo codice per fare l'Upload dei file in internet, non so se e' possibile ma lo vorrei tradurre in VB.NET, mi date una mano???
lo ho gia fatto io ma non mi funziona, eppure e' molto facile , forse mi sfugge qualcosa...
il codice:
<%@ Import Namespace="System.IO" %>
<%@ page Language="C#" debug="true" %>
<html>
<head>
<title></title>
<script language="C#" runat="server">
//This method is called when the 'upload' button id pressed
public void UploadFile(object sender , EventArgs E)
{
//check if the fileposted is bot null
if(myFile.PostedFile!=null)
{
//some string manipulations to extract the filename from the full file path
string nam = myFile.PostedFile.FileName ;
int i= nam.LastIndexOf("\\") ;
string newnm =nam.Substring(i) ;
//save the file to the destination path on your server
//change this path as per your needs (remember the path you specify should exist and have 'write' access)
//Note: I have used "c:\\" etc the "\\" is because I have to give a escape character
//in a string
myFile.PostedFile.SaveAs("c:\\inetpub\\wwwroot\\upload\\"+newnm) ;
//Get the various properties of the Uploaded file
fname.Text=myFile.PostedFile.FileName;
fenc.Text=myFile.PostedFile.ContentType ;
fsize.Text=myFile.PostedFile.ContentLength.ToString();
}
}
</script>
</head>
<body>
<center>
<form id="uploderform" method="post" action="FileUpload.aspx" enctype="multipart/form-data" runat="server" >
<table border="0">
<tr><td>
<input type="file" id="myFile" runat="server" >
</td></tr>
<tr><td>
<input type="button" value="Upload" OnServerClick="UploadFile" runat="server" >
</td></tr>
</table>
</form>
<br>
<br>
<table border="0">
<tr><td><b>File Details</b></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>File Name :</td>
<td><asp:label id="fname" text="" runat="server" /></td></tr>
<tr>
<td>File Encoding :</td>
<td><asp:label id="fenc" runat="server" /></td></tr>
<tr>
<td>File Size :(in bytes)</td>
<td><asp:label id="fsize" runat="server" /></td></tr>
</table>
</center>
</body>
</html>
lo ho gia fatto io ma non mi funziona, eppure e' molto facile , forse mi sfugge qualcosa...
il codice:
<%@ Import Namespace="System.IO" %>
<%@ page Language="C#" debug="true" %>
<html>
<head>
<title></title>
<script language="C#" runat="server">
//This method is called when the 'upload' button id pressed
public void UploadFile(object sender , EventArgs E)
{
//check if the fileposted is bot null
if(myFile.PostedFile!=null)
{
//some string manipulations to extract the filename from the full file path
string nam = myFile.PostedFile.FileName ;
int i= nam.LastIndexOf("\\") ;
string newnm =nam.Substring(i) ;
//save the file to the destination path on your server
//change this path as per your needs (remember the path you specify should exist and have 'write' access)
//Note: I have used "c:\\" etc the "\\" is because I have to give a escape character
//in a string
myFile.PostedFile.SaveAs("c:\\inetpub\\wwwroot\\upload\\"+newnm) ;
//Get the various properties of the Uploaded file
fname.Text=myFile.PostedFile.FileName;
fenc.Text=myFile.PostedFile.ContentType ;
fsize.Text=myFile.PostedFile.ContentLength.ToString();
}
}
</script>
</head>
<body>
<center>
<form id="uploderform" method="post" action="FileUpload.aspx" enctype="multipart/form-data" runat="server" >
<table border="0">
<tr><td>
<input type="file" id="myFile" runat="server" >
</td></tr>
<tr><td>
<input type="button" value="Upload" OnServerClick="UploadFile" runat="server" >
</td></tr>
</table>
</form>
<br>
<br>
<table border="0">
<tr><td><b>File Details</b></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>File Name :</td>
<td><asp:label id="fname" text="" runat="server" /></td></tr>
<tr>
<td>File Encoding :</td>
<td><asp:label id="fenc" runat="server" /></td></tr>
<tr>
<td>File Size :(in bytes)</td>
<td><asp:label id="fsize" runat="server" /></td></tr>
</table>
</center>
</body>
</html>