I am new to SharePoint.
I have given the flow below.
• I have a button in visual web part called Archive.
• On Click of the button I like to move the folder inside the site(A) to another site(B).
• I used this code to move a folder from a site to another site.
I am getting an error
:
"Folder 'Archive' not exist".
What is the reason for this issue?
protected void btnArchive_Click(object sender, EventArgs e)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
SPWeb spWeb = SPContext.Current.Web;
spWeb.AllowUnsafeUpdates = true;
string strURl = @"http://server/site/Shared%20Documents/Copies";
SPFolder spFolder = spWeb.GetFolder(strURl);
string sDestURL = @"http://server/site/archive/Shared%20Documents/";
using (SPSite site = new SPSite(sDestURL))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
string sSiteName = spWeb.Name;
SPFolder subSiteFolder = web.GetFolder(sDestURL + sSiteName);
if (!subSiteFolder.Exists)
{
subSiteFolder = web.Folders.Add(sSiteName);
web.Update();
}
spFolder.CopyTo(sDestURL);
}
}
});
}
catch (Exception Ex)
{
lblMesg.Text = "Error:" + Ex.Message;
}
}