Forum Moderators: open
<html>
<Script Language="VB" RunAt="Server">
Sub Page_Load(Sender as Object, e as EventArgs)
Dim MyPath, MyName as string
' Display the names in C:\ that represent directories.
MyPath = "D:\Data\websites\clients\magneforcess\magne-reseller" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
if MyName="" ' The folder is not there & to be created
MkDir("D:\Data\websites\clients\magneforcess\magne-reseller") 'Folder created
span2.InnerHtml="A Folder (D:\Data\websites\clients\magneforcess\magne-reseller) is created at the Page_Load"
end if
End Sub
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
' Let us recover only the file name from its fully qualified path at client
Dim strFileName as string
strFileName = MyFile.PostedFile.FileName
Dim c as string = System.IO.Path.GetFileName(strFileName) ' only the attched file name not its path
' Let us Save uploaded file to server at C:\ServerFolder\
Try
MyFile.PostedFile.SaveAs("D:\Data\websites\clients\magneforcess\magne-reseller" + c)
Span1.InnerHtml = "Your File Uploaded Sucessfully at server as : D:\Data\websites\clients\magneforcess\magne-reseller" & c
catch Exp as exception
span1.InnerHtml = "An Error occured. Please check the attached file"
UploadDetails.visible = false
span2.visible=false
End Try
End Sub
</Script>
</head>
<body bgcolor="#000033" topmargin="0">
<div align="center"><img src="header.gif" name="image1" width="900" height="128" border="0" usemap="#Map" id="image1">
<map name="Map">
<area shape="rect" coords="5,105,51,126" href="index.html" alt="Home">
<area shape="rect" coords="87,106,161,126" href="products.html" alt="Products" onMouseOver="MM_showMenu(window.mm_menu_0331120226_0,87,126,null,'image1')" onMouseOut="MM_startTimeout();">
<area shape="rect" coords="203,103,270,127" href="services.html" alt="Services">
<area shape="rect" coords="307,103,393,124" href="login.asp" alt="Downloads">
<area shape="rect" coords="424,103,524,125" href="news.html" alt="News">
<area shape="rect" coords="553,104,636,127" href="corporate.html" alt="Corporate">
</map>
<img src="headlines.gif" width="900" height="114"></div>
<table width="900" height="634" border="0" align="center" bgcolor="#CCCCCC">
<tr>
<td valign="bottom"> </td>
<td height="76" valign="middle"> <div align="left"><font color="#000033" size="6" face="Arial, Helvetica, sans-serif"><strong>UPLOAD<br />
<img src="line.png" width="665" height="8"><br />
</strong></font></div></td>
<td width="10" rowspan="2" valign="top"> </td>
<td width="180" rowspan="2" valign="top"><p align="center"><strong><u><font size="4" face="Arial, Helvetica, sans-serif"><img src="button.gif" width="5" height="5" align="absmiddle"><a href="products.html">PRODUCTS</a></font></u></strong><img src="button.gif" width="5" height="5" align="absmiddle"><br />
<br />
<br />
<br />
<p align="center"> <strong><u><font size="4" face="Arial, Helvetica, sans-serif"><img src="button.gif" width="5" height="5" align="absmiddle"><a href="services.html">SERVICES</a></font></u></strong><img src="button.gif" width="5" height="5" align="absmiddle"><br />
<br />
<br />
<br />
<p align="center"><strong><u><font size="4" face="Arial, Helvetica, sans-serif"><img src="button.gif" width="5" height="5" align="absmiddle"><a href="news.html">NEWS/EVENTS</a></font></u></strong><img src="button.gif" width="5" height="5" align="absmiddle"><br />
<br />
<br />
<br />
<p align="center"><strong><u><font size="4" face="Arial, Helvetica, sans-serif"><img src="button.gif" width="5" height="5" align="absmiddle"><a href="corporate.html">CORPORATE</a></font></u></strong><img src="button.gif" width="5" height="5" align="absmiddle"><br />
</p></td>
<td width="8" rowspan="2" valign="top"> <div align="center">
<p> </p>
<p> </div>
<div align="center">
<p> </p>
</div></td>
</tr>
<tr>
<td width="1" valign="top"> </td>
<td width="679" height="196" valign="top"> <div align="center">
<div align="center"></div>
<div align="left">
<Form Method="Post" EncType="Multipart/Form-Data" RunAt="Server">
Choose Your File To Upload : <BR>
<Input ID="MyFile" Type="File" RunAt="Server" Size="40"> <BR>
<BR>
<Input Type="Submit" Value="Upload" OnServerclick="Upload_Click" RunAt="Server">
<P>
<Div ID="UploadDetails" Visible="False" RunAt="Server">
File Name: <Span ID="FileName" RunAt="Server"/> <BR>
File Content: <Span ID="FileContent" RunAt="Server"/>
<BR>
File Size: <Span ID="FileSize" RunAt="Server"/>bytes
<BR></Div>
<Span ID="Span1" Style="Color:Red" RunAt="Server"/>
<Span ID="Span2" Style="Color:Red" RunAt="Server"/>
</Form>
At some point you may hit permissions isssues attempting to write the file to the folder on the server, but I don't think you're there yet.
I am trying to send the file into a file that has been created by the name of magne-reseller. This file has writeable and readable permissions.
When my file is put on the server it is in my root with all the other pages and the name has been changed from brinkley.jpg to magne-resellerbrinkley.jpg. Below is my code, do you see what I am doing wrong?
<html>
<Script Language="VB" RunAt="Server">
Sub Page_Load(Sender as Object, e as EventArgs)
Dim MyPath, MyName as string
' Display the names in C:\ that represent directories.
MyPath = "D:\Data\websites\clients\magneforcess\magne-reseller" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
End Sub
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
' Let us recover only the file name from its fully qualified path at client
Dim strFileName as string
strFileName = MyFile.PostedFile.FileName
Dim c as string = System.IO.Path.GetFileName(strFileName) ' only the attched file name not its path
' Let us Save uploaded file to server at C:\ServerFolder\
Try
MyFile.PostedFile.SaveAs("D:\Data\websites\clients\magneforcess\magne-reseller" + c)
Span1.InnerHtml = "Your File Uploaded Sucessfully at server as : D:\Data\websites\clients\magneforcess\magne-reseller" & c
catch Exp as exception
span1.InnerHtml = "An Error occured. Please check the attached file"
UploadDetails.visible = false
span2.visible=false
End Try
End Sub
</Script>