用于自定义列表的SharePoint备份工具

我有一个包含三个自定义列表的SharePoint 2013文档库。 每天一次,我想将自定义列表备份为excel文档。用于自定义列表的SharePoint备份工具

SharePoint 2013中是否有可以配置为循环任务的内置功能?

还是应该使用PowerShell或CSOM编写脚本或由Windows任务运行的应用程序?

回答:

你不要有任何OOB功能,要做到这一点,我有同样的REQ和我写了一个实用程序 - PFB代码 - 这会给你的O/P在.csv文件

类节目

{

private static DataTable dataTable;

private static SPList list;

静态无效的主要(字串[] args)

{

尝试

{

Console.WriteLine("Site Url: "); 

string _siteUrl = Console.ReadLine();

if (!string.IsNullOrEmpty(_siteUrl))

{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite site = new SPSite(_siteUrl))

{

if (site != null)

{

SPWeb web = site.RootWeb;

if (web != null)

{

// Export List code segment

Console.WriteLine("List Name:");

string _listName = Console.ReadLine();

if (!string.IsNullOrEmpty(_listName))

{

list = web.Lists[_listName];

if (list != null)

{

dataTable = new DataTable();

//Adds Columns to SpreadSheet

InitializeExcel(list, dataTable);

string _schemaXML = list.DefaultView.ViewFields.SchemaXml;

if (list.Items != null && list.ItemCount > 0)

{

foreach (SPListItem _item in list.Items)

{

DataRow dr = dataTable.NewRow();

foreach (DataColumn _column in dataTable.Columns)

{

如果(dataTable.Columns [_column.ColumnName]!= NULL & & _item [_column.ColumnName]!= null)

    { 

dr [_column.ColumnName] = _item [_column.ColumnName] .ToString();

    } 

}

dataTable.Rows.Add(dr);

}

}

}

}

System.Web.UI.WebControls.DataGrid网格=新System.Web.UI.WebControls.DataGrid();

 grid.HeaderStyle.Font.Bold = true; 

grid.DataSource = dataTable;

grid.DataBind();

using (StreamWriter streamWriter = new StreamWriter("C:\\" + list.Title + ".xls", false, Encoding.UTF8))

{

using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(streamWriter))

{

grid.RenderControl(htmlTextWriter);

}

}

Console.WriteLine("File Created");

#endregion

}

}

}

});

}

}

catch (Exception ex)

{

Console.WriteLine("Error: " + ex.Message);

}

Console.ReadLine();

}

//创建EXCEL funution

公共静态无效InitializeExcel(SPList列表,数据表_datatable)

{

if (list != null) 

{

string _schemaXML = list.DefaultView.ViewFields.SchemaXml;

if (list.Items != null && list.ItemCount > 0)

{

foreach (SPListItem _item in list.Items)

{

foreach (SPField _itemField in _item.Fields)

{

if (_schemaXML.Contains(_itemField.InternalName))

{

if (_item[_itemField.InternalName] != null)

{

if (!_datatable.Columns.Contains(_itemField.InternalName))

{

_datatable.Columns.Add(new DataColumn(_itemField.StaticName, Type.GetType("System.String")));

}

}

}

}

}

}

}

}

}

以上是 用于自定义列表的SharePoint备份工具 的全部内容, 来源链接: utcz.com/qa/257308.html

回到顶部