Reply to topic
file upload in a form
danimak


Joined: 03 Sep 2007
Posts: 2
Reply with quote
This is probably going to be a very basic question, but here goes: I understand how to make forms and have them sent to me by e-mail using an aspmailform.asp file. Now, I've added a file upload to the form, but do not know how to access files that people upload. According to this page, http://www.hostmysite.com/support/programming/aspupload/, I am supposed to add an uploadscript.asp file and add this command to the HTML form page: ACTION="uploadscript.asp. My question is 1) what, then, happens to the aspmailform.asp instructions for the form info to be e-mailed to me, and 2) once I add the uploadscript.asp file, where do I get the file?

I know this is a basic programming question but any help would be appreciated.
whitesites


Joined: 05 Jul 2004
Posts: 176
Location: Houston, TX
Reply with quote
If you are running asn ASP site I can't help you, but if you are running a asp.net site forget anything the support sections of the HMS support tell you. Write your own script to get the job done. Its not hard at all. I will write you some code to show you how

I have realized that there are thousands of new .NET guys out there with questions like this, so if you want to learn more checkout my http://blog.whitesites.com. There isn't much there right now, but in the future I will be adding lots of .NET articles. I am a ANTI visual studio guy, so all my examples will be perfect for those of use who prefer to do things using notepad or dreamweaver. I also don't use complex classes, and stick to simple functions that noobies can easily understand.
whitesites


Joined: 05 Jul 2004
Posts: 176
Location: Houston, TX
Reply with quote
Here is the an example

Code:

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ import Namespace="System.Data" %>
<script language="C#" runat="server">

void Page_Load(Object Src, EventArgs E){

   //nothing todo here
   
}
   
void UploadBtn_Click(Object sender, EventArgs e){
   
      // get the name of the file you uploaded
      String UploadedFile = MyFile.PostedFile.FileName;
      int ExtractPos =   UploadedFile.LastIndexOf("\\") + 1;
   
      //to retrieve only Filename from the complete path
      String UploadedFileName =  UploadedFile.Substring(ExtractPos,UploadedFile.Length - ExtractPos);
       
       // Save uploaded file to server
       MyFile.PostedFile.SaveAs(Server.MapPath("folder_in_your_root/"+ UploadedFileName));
   
      Response.Write("Completed");
   }

</script>

<html>
<head>
<title>Example</title>
</head>
<body><form runat="server">
<asp:label id="headcode" runat="server"/>
<input name="file" type="file" id="MyFile" runat="server" />
<input name="submit" type="submit" value="Upload!" runat="server" onserverclick="UploadBtn_Click" />
</body></form>
</html>



Just make sure you have given "network service" full permissions to whatever space on the server you want the file to be written to
danimak


Joined: 03 Sep 2007
Posts: 2
Reply with quote
Thanks for posting the example of the script, whitesites. But where does this script go? Can I put it in the aspmailform.asp file I already have for the rest of the form information?
whitesites


Joined: 05 Jul 2004
Posts: 176
Location: Houston, TX
Reply with quote
that is an aspx script and I don't think it will work with asp. That script is setup to be standalone. I recommend you use a asp.net instead of asp. Better to learn the new than the learn the old.
file upload in a form
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic