Reply
Help! ASP(.NET)/Image Upload/GoDaddy
Old 03-26-2009, 11:10 AM Help! ASP(.NET)/Image Upload/GoDaddy
Junior Talker

Posts: 1
Trades: 0
Dear all,

I should probually know better, but after 7/8 years of not touching ASP I have come back to it to make a personal website I have had an idea for.

I was never that great in the first place, but everything has moved on and I a struggling. I have managed to contenect to my MS SQL database and manipulate data in and out using stored Procs (which I was pleased with), but I have come up against a total brick wall with regard to uploading images.

I need to allow users to upload a jpeg image, then automatically resize it and save two copies one large (max 500px wide) and one small (100px) in a directory on my site (uploaded_images).

I am using GoDaddy and I have created a folder with read & write permissions.

I know that to do this in traditional ASP I would need to use AspUpload, but I cannot afford the £££'s that would cost.

Everywhere I look tells me that I can do it in 'one or two easy lines of code' in Asp.Net, but I have never used this and so quite out of my depth.

I have downloaded this code which I run as upload.aspx, but I just get a runtime error (which is the first time i have seen this error message - I am used to the old ASP errors)

The code is:

<%@ 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 = "/uploaded_images/" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.

if MyName="" ' The folder is not there & to be created
MkDir("/uploaded_images/") 'Folder created
span2.InnerHtml="A Folder (/uploaded_images/) 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 /uploaded_images/


Try

MyFile.PostedFile.SaveAs("/uploaded_images/" + c)
Span1.InnerHtml = "Your File Uploaded Sucessfully at server as : /uploaded_images/" & 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>
<Body>

<Font Color="DarkGreen" Face=Helvetica Size=5> <B>Uploading In ASP.Net - A Rich Uploading !
</Font>
<HR Size="2" Color=Black >
<P>

<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>
<HR Size="2" Color=Black>

</Body>
</html>

I am not expecting people to write the code for me (although I would never look a gift horse in the mouth!), but if you could point me in the direct of a really simple step-by-step tutorial that would be great or make some suggestions on the above.

Many thanks,

James
JamesJ is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 04-11-2009, 12:41 AM Re: Help! ASP(.NET)/Image Upload/GoDaddy
Skilled Talker

Posts: 69
Trades: 0
I'm not sure what size images your uploading but you'll need to know that by default there is a 4mb limit. You can change this by changing the MaxRequestLength in the web.config file (if it's not there you'll need to add it).

Try the following (sorry it's c#):

in the aspx page use this:<asp:FileUpload ID="fileToBeUploaded" runat="server" />

add the following to the click event:

string fn = System.IO.Path.GetFileName(fileToBeUploaded.Posted File.FileName);
fileToBeUploaded.SaveAs(Server.MapPath("/upload_folder/") + fn);

that's all you need. This is the most basic way for using the upload control. If you need any other help let me know.
stbuchok is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help! ASP(.NET)/Image Upload/GoDaddy
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.11249 seconds with 13 queries