file copy question

Discussion in 'ASP .Net' started by Paul, Jun 12, 2008.

  1. Paul

    Paul Guest

    Hi just wondering if there is any sample code to copy files from one
    directory into another with the code behind a button click event? Using c#
    vs2005.
    Thanks.
    --
    Paul G
    Software engineer.
    Paul, Jun 12, 2008
    #1
    1. Advertising

  2. You need to import the System.IO namespace :

    <%@ Import Namespace="System.IO" %>

    Then, for your code :

    File.Copy("C:\\Dir1\\file.ext", @"C:\AnotherDir\file.ext");

    Feel free to substitute variables for the actual paths.
    You can also use different drives.

    Make sure your ASP.NET account has write permissions
    to the directory where the file is being copied to.






    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ======================================
    "Paul" <> wrote in message news:...
    > Hi just wondering if there is any sample code to copy files from one
    > directory into another with the code behind a button click event? Using c#
    > vs2005.
    > Thanks.
    > --
    > Paul G
    > Software engineer.
    Juan T. Llibre, Jun 12, 2008
    #2
    1. Advertising

  3. I noticed, after posting, that you requested code-behind and C#.

    Instead of "importing", add the reference to System.IO to your code-behind :

    using System.IO;




    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ======================================
    "Juan T. Llibre" <> wrote in message news:...
    > You need to import the System.IO namespace :
    >
    > <%@ Import Namespace="System.IO" %>
    >
    > Then, for your code :
    >
    > File.Copy("C:\\Dir1\\file.ext", @"C:\AnotherDir\file.ext");
    >
    > Feel free to substitute variables for the actual paths.
    > You can also use different drives.
    >
    > Make sure your ASP.NET account has write permissions
    > to the directory where the file is being copied to.
    >
    >
    >
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ======================================
    > "Paul" <> wrote in message news:...
    >> Hi just wondering if there is any sample code to copy files from one
    >> directory into another with the code behind a button click event? Using c#
    >> vs2005.
    >> Thanks.
    >> --
    >> Paul G
    >> Software engineer.

    >
    >
    >
    Juan T. Llibre, Jun 12, 2008
    #3
  4. Steve C. Orr [MCSD, MVP, CSM, ASP Insider], Jun 12, 2008
    #4
  5. Paul

    Paul Guest

    Thanks for the responses, looks like it is easy to impliment once you have
    the correct namespace.
    --
    Paul G
    Software engineer.


    "Steve C. Orr [MCSD, MVP, CSM, ASP Inside" wrote:

    > How about this?
    > http://msdn.microsoft.com/en-us/library/system.io.file.copy(VS.71).aspx
    >
    > --
    > I hope this helps,
    > Steve C. Orr,
    > MCSD, MVP, CSM, ASPInsider
    > http://SteveOrr.net
    > http://iPhonePlaza.net
    >
    >
    > "Paul" <> wrote in message
    > news:...
    > > Hi just wondering if there is any sample code to copy files from one
    > > directory into another with the code behind a button click event? Using
    > > c#
    > > vs2005.
    > > Thanks.
    > > --
    > > Paul G
    > > Software engineer.

    >
    Paul, Jun 12, 2008
    #5
  6. Hey, Steve, don't you hate it when code samples refer only to console apps ?

    I bet that has created many headaches for people looking for ASP.NET samples.
    It's easy for a beginner to stub his toe on the sample's translation to web app code.



    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ======================================
    "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <> wrote in message
    news:...
    > How about this?
    > http://msdn.microsoft.com/en-us/library/system.io.file.copy(VS.71).aspx
    >
    > --
    > I hope this helps,
    > Steve C. Orr,
    > MCSD, MVP, CSM, ASPInsider
    > http://SteveOrr.net
    > http://iPhonePlaza.net
    >
    >
    > "Paul" <> wrote in message news:...
    >> Hi just wondering if there is any sample code to copy files from one
    >> directory into another with the code behind a button click event? Using c#
    >> vs2005.
    >> Thanks.
    >> --
    >> Paul G
    >> Software engineer.

    >
    Juan T. Llibre, Jun 12, 2008
    #6
  7. Paul

    David Wier Guest

    It sure stubbed my toes a number of times, when I was first starting to
    learn ASP.Net - I had no idea what a console app was - and then when I did
    find out, it made me furious, since so many samples were written this way

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    "Juan T. Llibre" <> wrote in message
    news:...
    > Hey, Steve, don't you hate it when code samples refer only to console apps
    > ?
    >
    > I bet that has created many headaches for people looking for ASP.NET
    > samples.
    > It's easy for a beginner to stub his toe on the sample's translation to
    > web app code.
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ======================================
    > "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <> wrote in
    > message news:...
    >> How about this?
    >> http://msdn.microsoft.com/en-us/library/system.io.file.copy(VS.71).aspx
    >>
    >> --
    >> I hope this helps,
    >> Steve C. Orr,
    >> MCSD, MVP, CSM, ASPInsider
    >> http://SteveOrr.net
    >> http://iPhonePlaza.net
    >>
    >>
    >> "Paul" <> wrote in message
    >> news:...
    >>> Hi just wondering if there is any sample code to copy files from one
    >>> directory into another with the code behind a button click event? Using
    >>> c#
    >>> vs2005.
    >>> Thanks.
    >>> --
    >>> Paul G
    >>> Software engineer.

    >>

    >
    >
    David Wier, Jun 12, 2008
    #7
  8. Paul

    Paul Guest

    Yep in the past not noticing an example is a windows app I will start trying
    to impliment it in a web app until I can not find the class or namespace that
    they are using in the example!
    --
    Paul G
    Software engineer.


    "Juan T. Llibre" wrote:

    > Hey, Steve, don't you hate it when code samples refer only to console apps ?
    >
    > I bet that has created many headaches for people looking for ASP.NET samples.
    > It's easy for a beginner to stub his toe on the sample's translation to web app code.
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ======================================
    > "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <> wrote in message
    > news:...
    > > How about this?
    > > http://msdn.microsoft.com/en-us/library/system.io.file.copy(VS.71).aspx
    > >
    > > --
    > > I hope this helps,
    > > Steve C. Orr,
    > > MCSD, MVP, CSM, ASPInsider
    > > http://SteveOrr.net
    > > http://iPhonePlaza.net
    > >
    > >
    > > "Paul" <> wrote in message news:...
    > >> Hi just wondering if there is any sample code to copy files from one
    > >> directory into another with the code behind a button click event? Using c#
    > >> vs2005.
    > >> Thanks.
    > >> --
    > >> Paul G
    > >> Software engineer.

    > >

    >
    >
    >
    Paul, Jun 12, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Richter
    Replies:
    4
    Views:
    5,435
    Steve Richter
    Apr 18, 2005
  2. Alex
    Replies:
    2
    Views:
    1,199
  3. Replies:
    26
    Views:
    2,083
    Roland Pibinger
    Sep 1, 2006
  4. dave
    Replies:
    6
    Views:
    1,001
  5. MaggotChild

    File::Copy::copy With File Handles

    MaggotChild, Oct 18, 2011, in forum: Perl Misc
    Replies:
    2
    Views:
    491
    Ilya Zakharevich
    Oct 22, 2011
Loading...

Share This Page