翻譯|使用教程|編輯:李顯亮|2020-03-24 09:53:42.833|閱讀 367 次
概述:在某些情況下,可能需要從應(yīng)用程序中的Project Server /在線訪問項目信息。為了處理這種情況,在本文中,將展示如何使用C#在.NET應(yīng)用程序(ASP.NET等)或Web服務(wù)中的Project Server或Project Online上/從Project Server或Project Online創(chuàng)建/讀取項目。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Project Server和Online是由微軟提供的功能豐富的項目和項目組合管理解決方案。兩種解決方案都提供了幾乎相似的功能來創(chuàng)建和管理項目,但是,根據(jù)哪種解決方案完全符合您的要求,它們會有所不同。
例如,如果您希望本地解決方案對硬件和軟件具有更多控制權(quán),則可以選擇Project Server。另一方面,Project Online可以用作Project Server的基于云的實例,而無需您自己的基礎(chǔ)結(jié)構(gòu)。
在某些情況下,可能需要從應(yīng)用程序中的Project Server /在線訪問項目信息。為了處理這種情況,在本文中,將展示如何使用C#在.NET應(yīng)用程序(ASP.NET等)或Web服務(wù)中的Project Server或Project Online上/從Project Server或Project Online創(chuàng)建/讀取項目。
Aspose.Tasks for .NET已升級至V20.3,如果你還沒有用過Aspose.Tasks可以點擊這里下載最新版測試。
為了連接到Project Server,您需要了解以下詳細(xì)信息:
使用C#從Project Server讀取項目
以下是連接到Project Server并從中檢索項目列表的步驟。
下面的代碼示例演示如何使用C#從Project Server中讀取項目。
string url = "http://contoso.sharepoint.com"; string domain = "CONTOSO.COM"; string userName = "Administrator"; string password = "MyPassword"; var windowsCredentials = new NetworkCredential(userName, password, domain); var projectServerCredentials = new ProjectServerCredentials(url, windowsCredentials); ProjectServerManager manager = new ProjectServerManager(projectServerCredentials); var list = manager.GetProjectList(); foreach (var projectInfo in list) { Console.WriteLine("{0} - {1} - {2}", projectInfo.Id, projectInfo.CreatedDate, projectInfo.Name); }
在C#中的Project Server上創(chuàng)建項目
在Project Server上創(chuàng)建項目非常簡單。只需以與上一個示例相同的方式連接到Project Server,使用Project類加載項目文件(.mpp),然后調(diào)用ProjectServerManager.CreateNewProject()方法。
下面的代碼示例演示如何在C#中的Project Server上創(chuàng)建一個新項目。
string url = "http://contoso.sharepoint.com"; string domain = "CONTOSO.COM"; string userName = "Administrator"; string password = "MyPassword"; var project = new Project(@"sample.mpp"); var windowsCredentials = new NetworkCredential(userName, password, domain); var projectServerCredentials = new ProjectServerCredentials(url, windowsCredentials); ProjectServerManager manager = new ProjectServerManager(projectServerCredentials); manager.CreateNewProject(project);
使用Project Online與使用Project Server非常相似,只是在創(chuàng)建連接方面有所不同。為了連接到Project Online,需要了解以下詳細(xì)信息:
使用C#從Project Online讀取項目
以下是從在線項目中讀取項目的步驟:
下面的代碼示例演示如何從Project Online檢索項目列表。
string sharepointDomainAddress = "http://contoso.sharepoint.com"; string userName = "admin@contoso.onmicrosoft.com"; string password = "MyPassword"; var credentials = new ProjectServerCredentials(sharepointDomainAddress, userName, password); ProjectServerManager manager = new ProjectServerManager(credentials); var list = manager.GetProjectList(); foreach (var p in list) { Console.WriteLine("{0} - {1} - {2}", p.Name, p.CreatedDate, p.LastSavedDate); } foreach (var p in list) { var project = manager.GetProject(p.Id); Console.WriteLine("Project '{0}' loaded. Resources count: {1}", p.Name, project.Resources.Count); }
使用C#在Project Online上創(chuàng)建項目
以下是在在線項目上創(chuàng)建新項目的步驟:
下面的代碼示例演示如何使用C#在Project Online上創(chuàng)建一個新項目。
string sharepointDomainAddress = "http://contoso.sharepoint.com"; string userName = "admin@contoso.onmicrosoft.com"; string password = "MyPassword"; var credentials = new ProjectServerCredentials(sharepointDomainAddress, userName, password); var project = new Project(@"sample.mpp"); ProjectServerManager manager = new ProjectServerManager(credentials); manager.CreateNewProject(project);還想要更多嗎?您可以點擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn