using
System;
System.Collections.Generic;
System.Linq;
System.Text;
Microsoft.SharePoint;
namespace
CopyDocumentLibrariesRashu
{
class
Program
static
void
Main(
string
[] args)
try
Console.WriteLine(
"Hello, This tool will copy the the files between the folders specified. It will overwrite the file if it exists at the destination location"
);
"Please enter the URL of the source folder"
sourceURL = Console.ReadLine();
"Please enter the URL of the destination folder"
destinationURL = Console.ReadLine();
"do you want to copy a specific file?if yes then type y or else type anything else"
String fileDecision = Console.ReadLine();
String cFile =
.Empty;
if
(fileDecision ==
"y"
)
"Please enter the filename with extension of the file"
cFile = Console.ReadLine();
}
(SPSite sourceSite =
new
SPSite(sourceURL))
(SPWeb sourceWeb = sourceSite.OpenWeb())
(SPSite destinationSite =
SPSite(destinationURL))
(SPWeb destinationWeb = destinationSite.OpenWeb())
SPFolder sList = (SPFolder)sourceWeb.GetFolder(sourceURL);
SPFolder dList = (SPFolder)destinationWeb.GetFolder(destinationURL);
SPList dLibrary = destinationWeb.Lists[dList.ContainingDocumentLibrary];
SPFileCollection files = sList.Files;
(fileDecision !=
foreach
(SPFile ctFile
in
files)
byte
[] sbytes = ctFile.OpenBinary();
SPFile dFileName = dList.Files.Add(ctFile.Name, sbytes,
true
(dFileName.CheckOutStatus != SPFile.SPCheckOutStatus.None)
dFileName.CheckIn(
"Checking in"
else
SPFile desFile = sList.Files[sourceURL +
"/"
+ cFile];
[] sbytes = desFile.OpenBinary();
SPFile dFileName = dList.Files.Add(desFile.Name, sbytes,
destinationWeb.Update();
"The operation completed successfully"
Console.ReadLine();
catch
(Exception e)
Console.WriteLine(e.Message);
Gokan Ozcifci edited Revision 5. Comment: Formatting
Patris_70 edited Revision 3. Comment: deleted (en-US) from title
Craig Lussier edited Revision 2. Comment: added en-US to tags and title
Ed Price - MSFT edited Revision 1. Comment: Title and tags