Upload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex

    #1

    Upload

    Hi there!

    I'd like o k'now how to make un upload of a certain file
    to disk in ASP.

    Thank you for your time

  • Emil Kvarnhammar

    #2
    Re: Upload

    Hi,

    In ASP.NET you can upload a file using the File control. Add a File control
    from the HTML controls toolbox if using VS.NET or manually with the code:

    <INPUT id="File1" type="file" name="File1" runat="server">

    Now in CodeBehind you can use the File1.PostedFil e on for example
    a btnUpload click event like this:

    private void btnUpload_Click (object sender, System.EventArg s e)
    {
    if(File1.Posted File != null)
    File1.PostedFil e.SaveAs(@"c:\u ploadfolder\dat a.txt");
    }

    Note that you must have write privileges to the folder you upload to set
    properly for the user that runs the ASP.NET app.

    Good luck!
    /Emil

    "Alex" <botinas@kaid4. com.pt> wrote in message
    news:0a9f01c34a d9$37482720$a60 1280a@phx.gbl.. .[color=blue]
    > Hi there!
    >
    > I'd like o k'now how to make un upload of a certain file
    > to disk in ASP.
    >
    > Thank you for your time
    >[/color]


    Comment

    • Kevin Spencer

      #3
      Re: Upload

      You can also use a plain vanilla 'input type="file"' in your page, and in
      the PostBack, you can get uploaded files from the Request.Files collection.
      Make sure in either case that you set the encoding type of the form to
      "multipart/form-data".

      --
      HTH,

      Kevin Spencer
      Microsoft MVP
      ..Net Developer
      All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

      Big things are made up of
      lots of little things.

      "Emil Kvarnhammar" <emil@eqinox.co m> wrote in message
      news:%23qZU$vtS DHA.632@TK2MSFT NGP12.phx.gbl.. .[color=blue]
      > Hi,
      >
      > In ASP.NET you can upload a file using the File control. Add a File[/color]
      control[color=blue]
      > from the HTML controls toolbox if using VS.NET or manually with the code:
      >
      > <INPUT id="File1" type="file" name="File1" runat="server">
      >
      > Now in CodeBehind you can use the File1.PostedFil e on for example
      > a btnUpload click event like this:
      >
      > private void btnUpload_Click (object sender, System.EventArg s e)
      > {
      > if(File1.Posted File != null)
      > File1.PostedFil e.SaveAs(@"c:\u ploadfolder\dat a.txt");
      > }
      >
      > Note that you must have write privileges to the folder you upload to set
      > properly for the user that runs the ASP.NET app.
      >
      > Good luck!
      > /Emil
      >
      > "Alex" <botinas@kaid4. com.pt> wrote in message
      > news:0a9f01c34a d9$37482720$a60 1280a@phx.gbl.. .[color=green]
      > > Hi there!
      > >
      > > I'd like o k'now how to make un upload of a certain file
      > > to disk in ASP.
      > >
      > > Thank you for your time
      > >[/color]
      >
      >[/color]


      Comment

      Working...