Saturday, November 15, 2008

SharePoint - Copy Files (Code)

private SPWeb web;

private void Page_Load(object sender, System.EventArgs e)
{
web = SPControl.GetContextWeb(Context);
}


private void Button1_Click(object sender, System.EventArgs e)
{
int maxsize = Convert.ToInt32(TextBox1.Text);
SPFolder myfolder=web.GetFolder("Shared Documents");
SPFileCollection myfiles = myfolder.Files;
foreach (SPFile file in myfiles)
{
if (file.Length>(maxsize*1024))
{
Response.Write(file.Name + ": " + file.Length/1024 + "kb
");
file.CopyTo("Archive/"+file.Name,true);
}
}
}

No comments: