Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Problem when moving a file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arjen - 17 Jan 2008 12:58 GMT
Hi,

I want to move a file. Here is my code:

files[i].MoveTo(dirs[0].ToString());

Variable files[i] represents a file in the current directory (of the
executable).
Variable dirs[0] represents a subdirectory in the current directory.

When I run the code, my application 'hangs'. I don't know whats wrong.
The file and subdirectory exists.

Any help?

Thanks!
Lasse Vågsæther Karlsen - 17 Jan 2008 15:43 GMT
> Hi,
>
[quoted text clipped - 12 lines]
>
> Thanks!

To begin with it would've been nice if you explicitly stated the classes
you're using.

I'm assuming you are using the FileInfo.MoveTo method, and if you look
at the documentation for this, it expects a destination *file-name*, not
a directory.

As such, you need to specify what filename it should have in the target
directory as well.

Something like this:

files[i].MoveTo(Path.Combine(dirs[0].ToString(),
Path.GetFileName(files[i].Name)))

(note, untested, writing from documentation only)

Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

Arjen - 17 Jan 2008 16:21 GMT
> > Hi,
>
[quoted text clipped - 36 lines]
>
> - Tekst uit oorspronkelijk bericht weergeven -

Thanks for your reply. This works! Thanks!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.