file copy question

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

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.
 
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/
======================================
 
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 said:
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/
======================================
 
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 said:
 
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 said:
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/
======================================
 
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 said:
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/
======================================
 
Back
Top