Ejemplo n.º 1
0
        public void Process()
        {
            var list = GetList(_web);

            if (list == null)
            {
                return;
            }
            ClientObjectExtensions.EnsureProperties <List>(list, l => l.Id, l => l.RootFolder, l => l.RootFolder.Name);

            SetProperty("selectedListId", list.Id);
            SetProperty("selectedListUrl", list.RootFolder.Name);
            _control.JsonControlData = JsonUtility.Serialize <IDictionary <string, object> >(_properties);
        }
Ejemplo n.º 2
0
        protected override void ExecuteCmdlet()
        {
            if (!System.IO.Path.IsPathRooted(Path))
            {
                Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
            }

            ClientObjectExtensions.EnsureProperty <Microsoft.SharePoint.Client.Web, string>(SelectedWeb, w => w.ServerRelativeUrl);

            var folder = FileFolderExtensions.EnsureFolder(SelectedWeb, SelectedWeb.RootFolder, Folder);

            var fileUrl = UrlUtility.Combine(folder.ServerRelativeUrl, System.IO.Path.GetFileName(Path));

            // Check if the file exists
            if (Checkout)
            {
                try
                {
                    var existingFile = SelectedWeb.GetFileByServerRelativeUrl(fileUrl);
                    ClientObjectExtensions.EnsureProperty <File, bool>(existingFile, f => f.Exists);
                    if (existingFile.Exists)
                    {
                        FileFolderExtensions.CheckOutFile(SelectedWeb, fileUrl);
                    }
                }
                catch
                { // Swallow exception, file does not exist
                }
            }

            var file = folder.UploadFile(new FileInfo(Path).Name, Path, true);


            if (Values != null)
            {
                var item = file.ListItemAllFields;

                foreach (var key in Values.Keys)
                {
                    item[key as string] = Values[key];
                }

                item.Update();

                ClientContext.ExecuteQueryRetry();
            }

            if (Checkout)
            {
                FileFolderExtensions.CheckInFile(SelectedWeb, fileUrl, CheckinType.MajorCheckIn, CheckInComment);
            }


            if (Publish)
            {
                FileFolderExtensions.PublishFile(SelectedWeb, fileUrl, PublishComment);
            }

            if (Approve)
            {
                FileFolderExtensions.ApproveFile(SelectedWeb, fileUrl, ApproveComment);
            }

            WriteObject(file);
        }