我們正在讓某人手動將每週生成的Excel電子表格加載到SharePoint中。我確定有一種方法可以自動執行此操作。我對SharePoint並不瞭解很多,也許它確實很簡單,只需知道文件夾SharePoint將文件移動到其中並直接在其中複製即可。或者,也許它需要一些編程來讓它自動將放入給定目錄的新文件加載到SharePoint中。如何自動將文件加載到SharePoint中
無論哪種方式,我都希望有人在這裏指出我正確的方向。
我們正在讓某人手動將每週生成的Excel電子表格加載到SharePoint中。我確定有一種方法可以自動執行此操作。我對SharePoint並不瞭解很多,也許它確實很簡單,只需知道文件夾SharePoint將文件移動到其中並直接在其中複製即可。或者,也許它需要一些編程來讓它自動將放入給定目錄的新文件加載到SharePoint中。如何自動將文件加載到SharePoint中
無論哪種方式,我都希望有人在這裏指出我正確的方向。
您將需要使用SharePoint中的複製Web服務上載文件。我不確定您正在運行的SharePoint的版本是什麼,但我假設爲2007年。以下是示例project。
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()[email protected]"' 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);
}
你可以寫一個PowerShell腳本那份文件到通過WebDAV文檔庫:
假設你在HTTP有你的文檔庫://服務器/ SomeWeb/DocumentLibrary /文件夾:
copy-item somesheet.xlsx \\server\SomeWeb\DocumentLibrary\Folder
我其實從來沒有使用PowerShell,但我經常告訴自己我需要研究它。 'copy-item'是一個PowerShell命令還是我必須寫的功能? –
Copy-Item是一個內置的PowerShell命令。 – Stefan
對不起,忘了提及它是SP 2010.不知道這是否有所作爲... –
它不應該。 Web服務仍然可用。 –
太棒了,謝謝。 –