Forum Moderators: open

Message Too Old, No Replies

Upload with Asp.net

What am I doing wrong?

         

Blelisa

8:13 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Hello
I am trying to put an upload feature on my website using asp.net.
When I test it, I put my file in that I want to upload, I click on the upload button, the screen goes white, lower left hand corner says, finding web page, then after about 20 seconds I get cant find page and the page name says cannot find server. Can anyone see what I am doing wrong? Thanks!
<%@ Page Language="vb" %>

<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">&nbsp;</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">&nbsp;</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>&nbsp;</p>
<p>&nbsp;</div>
<div align="center">
<p>&nbsp;</p>
</div></td>
</tr>
<tr>
<td width="1" valign="top">&nbsp;</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>

RossWal

11:20 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



I remember going through some gyrations with this a year or so ago. If you view the source html within the browser, what is the action on the form? Does that look reasonable?

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.

tomasz

1:25 pm on Jun 11, 2005 (gmt 0)

10+ Year Member



try to move form tag before body tag

Blelisa

7:43 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



That was it RosWall, the action was too the wrong location.
I got it posting now but I have one more problem:

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>

RossWal

9:24 pm on Jun 14, 2005 (gmt 0)

10+ Year Member



I'm not sure what's going on. I did notice you are using both the + sign and & sign as conctenation operators. That looks funny to me. Do you mean to use the ampersand?

Blelisa

2:10 pm on Jun 15, 2005 (gmt 0)

10+ Year Member



RosWall,
Thanks for your help, I got it working! I had too many \ in my code! Thanks again