Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 25, 2012 03:50 PM by vicky1
Dec 20, 2012 01:31 PM|LINK
i am making one application where i have one sub folder name draftfiles and it has one more folder which name first i am fetching from the database.
and through that name i am matching the folder name which is in draftfiles and when it's getting i am trying to move that folder in one more folder which name is inboxfiles.
but i am not able to do it.
here is my code.
DirectoryInfo di1 = new DirectoryInfo(Server.MapPath("~/DraftFiles/"));
FileInfo fi = di1.GetFiles();
foreach (FileInfo fsi in fi)
if (fi.Length > 0)
if (foldername == fsi.Name)
in this foldername variable is there which i fetched from the database but wat is happening in foreach loop it's not getting the folder which is in draftfiles.
Dec 20, 2012 04:46 PM|LINK
You want to use File.Move Method found in the System.IO namespace.
Will looking something like (untested but should get you close):
File.Move(fsi.FullName, Path.Combine(Server.MapPath("~/InboxFiles") + foldername));
Side note: I would probably move the server.mappath to it's own variable to make it easier to debug and make sure that the correctly directory/filename are getting passed in... var myString = Server.MapPath("~/InboxFiles") + foldername);
Dec 25, 2012 02:17 AM|LINK
Move sub folder "subFolder" to the folder "Docs"
string newDirectoryPath = Server.MapPath("~/Docs");
string subCurrentDirectory = Server.MapPath("~/Docs/mov/subFolder");
Directory.Move(subCurrentDirectory, Path.Combine(newDirectoryPath, Path.GetFileName(subCurrentDirectory)));
Dec 25, 2012 03:50 PM|LINK
thanks it's working for me.
i am marking it as answer.