file copy question

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.
 
J

Juan T. Llibre

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.
 
J

Juan T. Llibre

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 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.
 
J

Juan T. Llibre

D

David Wier

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.
 
P

Paul

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top