Hi,
I would like demonstrate how to convert extensions of files in a SharePoint Library.
Here we go:
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPFolder destnationLibrary= web.Folders[libraryName];
SPFileCollection fileColl = destnationLibrary.Files;
ChangeFileNames(siteUrl, libraryName, destnationLibrary, fileColl);
web.AllowUnsafeUpdates = false;
MessageBox.Show("Extensions are Successfully Changed", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
=======================================================================
public static void ChangeFileNames(string siteUrl, string docLibraryName, SPFolder mylibrary, SPFileCollection actualfileColl)
{
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPFolder doclibrary = web.Folders[docLibraryName];
foreach (SPFile file in actualfileColl)
{
SPFileCollection fileColl = doclibrary.Files;
string eXtension = Path.GetExtension(file.Name);
if (eXtension != "")
{
switch (eXtension)
{
case ".doc":
string wordAutomationServiceName = "Word Automation Services";
ConversionJob job = new ConversionJob(wordAutomationServiceName);
job.Settings.UpdateFields = true;
job.AddFile(siteUrl + "/Shared%20Documents/sample.doc", siteUrl + "/Shared%20Documents/sample.docx");
job.Start(); // ConversionJob to check file is converting or not
fileColl.Add(file.Name + "x", file.OpenBinary());
fileColl.Delete(file.Url);
break;
case ".ppt":
fileColl.Add(file.Name + "x", file.OpenBinary());
fileColl.Delete(file.Url);
break;
case ".xls":
fileColl.Add(file.Name + "x", file.OpenBinary());
fileColl.Delete(file.Url);
break;
}
}
}
}
}
}
=======================================================================
Hope this helps!!!
I would like demonstrate how to convert extensions of files in a SharePoint Library.
Here we go:
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPFolder destnationLibrary= web.Folders[libraryName];
SPFileCollection fileColl = destnationLibrary.Files;
ChangeFileNames(siteUrl, libraryName, destnationLibrary, fileColl);
web.AllowUnsafeUpdates = false;
MessageBox.Show("Extensions are Successfully Changed", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
=======================================================================
public static void ChangeFileNames(string siteUrl, string docLibraryName, SPFolder mylibrary, SPFileCollection actualfileColl)
{
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPFolder doclibrary = web.Folders[docLibraryName];
foreach (SPFile file in actualfileColl)
{
SPFileCollection fileColl = doclibrary.Files;
string eXtension = Path.GetExtension(file.Name);
if (eXtension != "")
{
switch (eXtension)
{
case ".doc":
string wordAutomationServiceName = "Word Automation Services";
ConversionJob job = new ConversionJob(wordAutomationServiceName);
job.Settings.UpdateFields = true;
job.AddFile(siteUrl + "/Shared%20Documents/sample.doc", siteUrl + "/Shared%20Documents/sample.docx");
job.Start(); // ConversionJob to check file is converting or not
fileColl.Add(file.Name + "x", file.OpenBinary());
fileColl.Delete(file.Url);
break;
case ".ppt":
fileColl.Add(file.Name + "x", file.OpenBinary());
fileColl.Delete(file.Url);
break;
case ".xls":
fileColl.Add(file.Name + "x", file.OpenBinary());
fileColl.Delete(file.Url);
break;
}
}
}
}
}
}
=======================================================================
Hope this helps!!!
No comments:
Post a Comment