CSOM +创建新日历 [英] CSOM + Create New Calendar

查看:90
本文介绍了CSOM +创建新日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好


我正在寻找一段代码,通过它我可以创建日历。


基本上我正在迁移日历Project Online的另一个实例。在这样做时,我需要使用CalenderCreationInformation设置ID,名称和原始ID。


但遗憾的是,没有可用的代码示例。


有没有人知道它?




谢谢,Parth

解决方案

< blockquote>

使用C#

========

使用Microsoft.ProjectServer.Client; 
使用Microsoft.SharePoint.Client;
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Security;
使用System.Text;
使用System.Threading.Tasks;

名称空间ProjectCSOM_Govind
{
class Program
{
static void Main(string [] args)
{
using( ProjectContext projContext = new ProjectContext(" https://< tenant> .sharepoint.com / sites / pwa"))
{
SecureString password = new SecureString();
foreach(char c in"< password>" .ToCharArray())password.AppendChar(c);

//使用SharePoint方法加载凭据
projContext.Credentials = new SharePointOnlineCredentials(" account @< tenant> .onmicrosoft.com",password);

var cal = projContext.Calendars.Add(new CalendarCreationInformation()
{
Name =" New Calendar",
OriginalId = Guid.Parse(" < standard calendar GUID>")

});
cal.BaseCalendarExceptions.Add(new CalendarExceptionCreationInformation()
{
Name =" Vacation",
Start = new DateTime(2018,5,18),
Finish = new DateTime(2018,5,19),
RecurrenceFrequency =(int)CalendarRecurrenceType.Daily
});
projContext.Calendars.Update();
projContext.ExecuteQuery();

Console.ReadLine();
}
}
}
}


使用PowerShell

========= =======



 


calInformation = New-Object Microsoft.ProjectServer .Client.CalendarCreationInformation


calInformation.Name =" CSOM2中的新日历"


Hi

I am looking for a piece of code through which i can create calendar.

Basically I am migrating calendar from one instance of Project Online to another. and while doing so i need to set the ID, Name and Original Id using CalenderCreationInformation.

But unfortunately there is no code sample available out there.

Does any one has any idea about it?


Thanks, Parth

解决方案

Using C#
========

using Microsoft.ProjectServer.Client;
using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;

namespace ProjectCSOM_Govind
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ProjectContext projContext = new ProjectContext("https://<tenant>.sharepoint.com/sites/pwa"))
            {
                SecureString password = new SecureString();
                foreach (char c in "<password>".ToCharArray()) password.AppendChar(c);

                //Using SharePoint method to load Credentials
                projContext.Credentials = new SharePointOnlineCredentials("account@<tenant>.onmicrosoft.com", password);
                               
                var cal = projContext.Calendars.Add(new CalendarCreationInformation()
                {
                    Name = "New Calendar",
                    OriginalId = Guid.Parse("<standard calendar GUID>")

                });
                cal.BaseCalendarExceptions.Add(new CalendarExceptionCreationInformation()
                {
                    Name = "Vacation",
                    Start = new DateTime(2018, 5, 18),
                    Finish = new DateTime(2018, 5, 19),
                    RecurrenceFrequency = (int)CalendarRecurrenceType.Daily
                });
                projContext.Calendars.Update();
                projContext.ExecuteQuery();

                Console.ReadLine();
            }
        }
    }
}

Using PowerShell
================


calInformation=New-Object Microsoft.ProjectServer.Client.CalendarCreationInformation


calInformation.Name ="New Calendar from CSOM2"


这篇关于CSOM +创建新日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆