Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: File posting


Message #1 by "Coco Lua Suat Choo" <CocoL@a...> on Wed, 2 Jan 2002 15:12:55 +0800
I tried out the example of file posting from the asp.net quickstart but

the porgram only works when i run the .aspx page from the web server,

when calling the program from a computer the program doesn't seem to

work, anyone know why? here's the code





<html>

<head>



    <script language=3D"C#" runat=3D"server">



       void Button1_Click(object Source, EventArgs e) {



          if (Text1.Value =3D=3D "") {

             Span1.InnerHtml =3D "Error: you must enter a file name";

             return;

          }



          if (File1.PostedFile !=3D null) {

             try {



File1.PostedFile.SaveAs("D:\\Inetpub\\wwwroot\\"+Text1.Value);

                Span1.InnerHtml =3D "File uploaded successfully to

<b>c:\\temp\\"+Text1.Value+"</b> on the web server";

             }

             catch (Exception exc) {

                Span1.InnerHtml =3D "Error saving file

<b>c:\\temp\\"+Text1.Value+"</b><br>"+ exc.ToString();

             }

          }

       }



    </script>



</head>

<body>



    <h3><font face=3D"Verdana">HtmlInputFile Sample</font></h3>



    <form enctype=3D"multipart/form-data" runat=3D"server">



        Select File to Upload: <input id=3D"File1" type=3Dfile

runat=3D"server">



        <p>

        Save as filename (no path): <input id=3D"Text1" type=3D"text"

runat=3D"server">



        <p>

        <span id=3DSpan1 style=3D"font: 8pt verdana;" runat=3D"server" 

/>



        <p>

        <input type=3Dbutton id=3D"Button1" value=3D"Upload"

OnServerClick=3D"Button1_Click" runat=3D"server">



    </form>



</body>

</html>







  thanks!


  Return to Index