Esempio n. 1
0
        /*
         * Примеры
         * http://stackoverflow.com/questions/17057074/how-to-download-upload-files-from-to-sharepoint-2013-using-csom
         * http://msdn.microsoft.com/en-us/library/office/ee956524(v=office.14).aspx
         * http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx
         */
        public void UploadFileSp()
        {
            AppcConfig opt = new AppcConfig();
            string     url = opt.UrlSP;

            //string fullNameFile = this.Place_save_local + this.Name + "." + this.Format_file;
            string st_ex        = this.Name_Directory != null ? " (" + this.Name_Directory + ")" : ""; //Задублированная логика А если полное наименование засунуть в объект
            string fullNameFile = this.Place_save_local + this.Name + st_ex + "." + this.Format_file;

            //opt.FolderTempPath + this.Name +st_ex+ "."+ this.Format_file
            using (var clientContext = new ClientContext(url))
            {
                clientContext.Credentials = System.Net.CredentialCache.DefaultCredentials;
                //Вываливается если файл не был создан
                using (var fs = new FileStream(fullNameFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    var fi   = new FileInfo(fullNameFile);
                    var list = clientContext.Web.Lists.GetByTitle(this.PlaceSaveSp_name);
                    clientContext.Load(list.RootFolder);
                    clientContext.ExecuteQuery();
                    var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, fi.Name);
                    Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, fs, true);
                    Console.WriteLine("Кладём файл {0} в библиотеку {1} на портал {2}", this.Name, this.PlaceSaveSp_name, opt.UrlSP);
                }
            }
        }
Esempio n. 2
0
        public void CreateFileReport()//Создание файлов из рассылки на Sp
        {
            //Получаем системные параметры
            AppcConfig opt     = new AppcConfig();
            string     st_ex   = this.Name_Directory != null ? " (" + this.Name_Directory + ")" : "";
            string     curFile = GetReport(this.Path_report, this.Format_report, this.Param, opt.FolderTempPath + this.Name + st_ex + "." + this.Format_file);

            //Если такой файл создался, т.е. существует локально то

            this.Success = System.IO.File.Exists(curFile);
        }
Esempio n. 3
0
        public void UploadFileSp()
        {
            //Получаем системные параметры
            AppcConfig opt = new AppcConfig();

            this.Success = true;
            for (int j = 0; j < FilesAttach.Count; j++)
            {
                Console.WriteLine("Пытаемся создать " + FilesAttach[j].Name);
                RC_File p = FilesAttach[j];
                p.UploadFileSp();
                Console.WriteLine((p.Success ? "Успешное " : " неуспешное ") + "создание файла SP {0}", FilesAttach[j].Name);
                this.Success = this.Success && p.Success;
            }
            Console.WriteLine((this.Success ? "Успешное " : " неуспешное ") + "формирование файлов SP рассылки {0}", this.Name);
        }