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)
{
fsi.MoveTo(Path.Combine(Server.MapPath("~/InboxFiles"), foldername));
}
}
}
}
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.
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);
I learn by helping others. I may not always be correct but my intentions are good. If my answer helps please mark it as so.
vicky1
Member
32 Points
349 Posts
How to move folder from one subfolder to another folder which is on server.
Dec 20, 2012 01:31 PM|LINK
Hi,
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)
{
fsi.MoveTo(Path.Combine(Server.MapPath("~/InboxFiles"), foldername));
}
}
}
}
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.
thanks
cornball76
Participant
1126 Points
210 Posts
Re: How to move folder from one subfolder to another folder which is on server.
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);
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: How to move folder from one subfolder to another folder which is on server.
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)));Feedback to us
Develop and promote your apps in Windows Store
vicky1
Member
32 Points
349 Posts
Re: How to move folder from one subfolder to another folder which is on server.
Dec 25, 2012 03:50 PM|LINK
Hi,
thanks it's working for me.
i am marking it as answer.