0

我们让某人手动将每周生成的 Excel 电子表格加载到 SharePoint 中。我确信有一种方法可以自动执行此操作。我对 SharePoint 了解不多,也许它真的很简单,只需知道 SharePoint 将文件移动到的文件夹并直接将它们复制到那里。或者,它可能需要一些编程才能使其自动将放置在给定目录中的新文件加载到 SharePoint 中。

无论哪种方式,我都希望有人在这里为我指明正确的方向。

4

2 回答 2

2

您可以编写一个 PowerShell 脚本,通过 WebDav 将文档复制到文档库中:

假设您的文档库位于http://server/SomeWeb/DocumentLibrary/Folder

copy-item somesheet.xlsx \\server\SomeWeb\DocumentLibrary\Folder
于 2012-05-15T07:03:21.593 回答
2

您将需要使用 SharePoint 中的复制 Web 服务上传文件。我不确定您运行的是什么版本的 SharePoint,但我假设是 2007 年。这是一个示例项目

public void UploadFile(string destinationFolderPath,
                      byte[] fileBytes,
                      string fileName,
                      bool overwrite,
                      string sourceFileUrl,
                      string lastVersionUrl)
{

List<Sharepoint.FieldInformation> fields = new List<Sharepoint.FieldInformation>();
Sharepoint.FieldInformation fieldInfo;

fieldInfo = new Sharepoint.FieldInformation();
fieldInfo.Id = Microsoft.SharePoint.SPBuiltInFieldId.Title;
fieldInfo.Value = "New title";
fieldInfo.DisplayName = "Title";
fieldInfo.Type = YetAnotherMigrationTool.Library.SP2007.Sharepoint.FieldType.Text;
fieldInfo.InternalName = "Title";
fields.Add(fieldInfo);

string[] url;
if (string.IsNullOrEmpty(destinationFolderPath))
    url = new string[] { string.Format("{0}/{1}/{2}", _siteUrl, _name, fileName) };
else
    url = new string[] { string.Format("{0}/{1}/{2}{3}", _siteUrl, _name,    destinationFolderPath, fileName) };
Sharepoint.CopyResult[] result;

Sharepoint.Copy service = new Sharepoint.Copy();
service.Url = _siteUrl + "/_vti_bin/Copy.asmx";
service.Credentials = new NetworkCredential(Settings.Instance.User, Settings.Instance.Password);
service.Timeout = 600000;

uint documentId = service.CopyIntoItems(sourceFileUrl, url, fields.ToArray(), fileBytes, out result);
}

public void SetContentType(List<string> ids, string contentType)
{
ListsService.Lists service = new YetAnotherMigrationTool.Library.SP2007.ListsService.Lists();
service.Url = _siteUrl + "/_vti_bin/Lists.asmx";
service.Credentials = new NetworkCredential(Settings.Instance.User, Settings.Instance.Password);

string strBatch = "";
for (int i = 1; i <= ids.Count; i++)
{
    strBatch += @"<Method ID='"+i.ToString()+@"' Cmd='Update'><Field Name='ID'>" + ids[i-1] + "</Field><Field Name='ContentType'>"+contentType+"</Field></Method>";
}
XmlDocument xmlDoc = new XmlDocument();
XmlElement elBatch = xmlDoc.CreateElement("Batch");
elBatch.SetAttribute("OnError", "Continue");
elBatch.SetAttribute("ListVersion", "10");
elBatch.SetAttribute("ViewName", "");
elBatch.InnerXml = strBatch;

result = service.UpdateListItems(_name, elBatch);
}
于 2012-05-15T07:05:44.633 回答