示例#1
0
        void FileType_DataInit(ClientContextMethod client, Microsoft.SharePoint.Client.FileCollection fileCollection)
        {
            foreach (var file in fileCollection)
            {
                DataGridItemLb lb         = new DataGridItemLb();
                PropertyInfo[] propertyes = lb.GetType().GetProperties();

                //加载文档创建者
                client.LoadMethod(file.Author);
                //加载文档修改者
                client.LoadMethod(file.ModifiedBy);
                //加载文档版本控制
                client.LoadMethod(file.Versions);

                propertyes[0].SetValue(lb, file.Name, null);
                propertyes[1].SetValue(lb, file.Author.Title, null);
                propertyes[2].SetValue(lb, file.ModifiedBy.Title, null);
                propertyes[3].SetValue(lb, file.TimeCreated.ToString(), null);
                propertyes[4].SetValue(lb, System.IO.Path.GetExtension(file.ServerRelativeUrl).Replace(".", ""), null);
                propertyes[5].SetValue(lb, file.UIVersionLabel, null);
                propertyes[6].SetValue(lb, file.Versions.Count.ToString(), null);
                propertyes[7].SetValue(lb, file.TimeLastModified.ToString(), null);

                dataList.Add(lb);
                this.datagrid.Items.Add(lb);
            }
        }
示例#2
0
        public DocumentDataGrid(ClientContextMethod client, Microsoft.SharePoint.Client.FileCollection fileCollection, string folderName, string webSiteUrl)
        {
            InitializeComponent();
            FileType_ParemesInit(client, fileCollection);
            this.fatherFolderName = folderName;
            this.clientMethod     = client;
            this.webSiteUri       = webSiteUrl;

            //书本快捷子菜单
            TbgMenuItem menuItemRemoveFile = new TbgMenuItem("删除文档", "分配任务");
            //书架快捷子菜单
            TbgMenuItem menuItemDowndLoad = new TbgMenuItem("下载该文档", "查看详情");
            //书架快捷子菜单
            TbgMenuItem menuItemCheckOut = new TbgMenuItem("签出该文档", "查看详情");
            //书架快捷子菜单
            TbgMenuItem menuItemCheckIn = new TbgMenuItem("签入该文档", "查看详情");

            //菜单加载子项
            menu.Items.Add(menuItemRemoveFile);
            //菜单加载子项
            menu.Items.Add(menuItemDowndLoad);
            //菜单加载子项
            menu.Items.Add(menuItemCheckOut);
            //菜单加载子项
            menu.Items.Add(menuItemCheckIn);

            //删除文档
            menuItemRemoveFile.Click += new RoutedEventHandler(menuItemRemoveFile_Click);
            //下载文档
            menuItemDowndLoad.Click += new RoutedEventHandler(menuItemDowndLoad_Click);
            //签出文档
            menuItemCheckOut.Click += new RoutedEventHandler(menuItemCheckOut_Click);
            //签入文档
            menuItemCheckIn.Click += new RoutedEventHandler(menuItemCheckIn_Click);
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Creating client context
            using (ClientContext context = GetClientContext(siteUrl, userName, password))
            {
                //Creating web object
                Web  web  = context.Web;
                List list = web.Lists.GetByTitle(documentLibrary);
                context.Load(list.RootFolder.Files);
                context.ExecuteQuery();
                //Got file collection from document library post authentication
                Microsoft.SharePoint.Client.FileCollection files = list.RootFolder.Files;


                //iterating the file collection to create the html
                context.Load(web.RootFolder);
                context.ExecuteQuery();

                foreach (Microsoft.SharePoint.Client.File file in files)
                {
                    HtmlAnchor anchor = new HtmlAnchor();
                    anchor.HRef      = rootSiteUrl + file.ServerRelativeUrl;
                    anchor.Title     = file.Name;
                    anchor.InnerText = file.Name;
                    anchor.Target    = "_Parent";
                    documents.Controls.Add(anchor);

                    documents.Controls.Add(new LiteralControl("<br />"));
                }
            }
        }
        public string Render(SP.FileCollection attachments, string url)
        {
            var baseUrl           = (new Uri(url)).GetLeftPart(UriPartial.Authority);
            var attachmentsMarkup = new StringBuilder();

            foreach (var attachment in attachments)
            {
                attachmentsMarkup.AppendFormat("<a href='{0}' target='_blank'>{1}</a><br/>", baseUrl + attachment.ServerRelativeUrl, attachment.Name);
            }
            return(attachmentsMarkup.ToString());
        }
        public string AttachmentNames(SP.FileCollection attachments)
        {
            if (attachments != null)
            {
                var names = new List <string>();

                foreach (SP.File file in attachments)
                {
                    names.Add(file.Name);
                }

                return(string.Join("|", names.ToArray()));
            }
            return(string.Empty);
        }
示例#6
0
        void item_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Microsoft.SharePoint.Client.List list = (sender as TbgTreeItem).List;

            Microsoft.SharePoint.Client.FileCollection fileCollection = (sender as TbgTreeItem).FileCollection;

            this.txtTittle.Text = (sender as TbgTreeItem).Header.ToString();
            if (list.BaseTemplate.Equals(100))
            {
                DocumentDataGrid dataGrid = new DocumentDataGrid(client, list, this.txtTittle.Text, webSiteUri);
                bordMain.Child = dataGrid;
            }
            else
            {
                DocumentDataGrid dataGrid = new DocumentDataGrid(client, fileCollection, this.txtTittle.Text, webSiteUri);
                dataGrid.datagrid.RowStyle = dataGrid.Resources["MenuGet"] as Style;
                bordMain.Child             = dataGrid;
            }
        }
示例#7
0
        public void FileType_ParemesInit(ClientContextMethod client, Microsoft.SharePoint.Client.FileCollection fileCollection)
        {
            this.dicTittleList.Clear();
            this.datagrid.Columns.Clear();

            client.LoadMethod(fileCollection);
            dicTittleList.Add("文件名称", "str1");
            dicTittleList.Add("创建人", "str2");
            dicTittleList.Add("编辑人", "str3");
            dicTittleList.Add("创建时间", "str4");
            dicTittleList.Add("文件类型", "str5");
            dicTittleList.Add("最新版本号", "str6");
            dicTittleList.Add("版本数量", "str7");
            dicTittleList.Add("最后一次修改时间", "str8");

            TitleInit(dicTittleList);

            FileType_DataInit(client, fileCollection);
        }
示例#8
0
        //dosya yolu ağacındaki bütün dosyaları döküman kitaplığına kaydeder
        public void UploadFileToDocumnetLibrary(File values)
        {
            var list = web.Lists.GetByTitle(StaticHelper.Listname);

            cContext.Load(list);
            cContext.Load(list.RootFolder);
            cContext.ExecuteQuery();

            Microsoft.SharePoint.Client.Folder folder = web.GetFolderByServerRelativeUrl(list.RootFolder.ServerRelativeUrl /*+ "/DESKTOP-KPK9VT0/Users/ysu"*/ + values.Path);

            FileCreationInformation fci = new FileCreationInformation
            {
                Url       = /*"kampanya hata.txt"*/ values.Name,
                Content   = System.IO.File.ReadAllBytes(/*"\\\\DESKTOP-KPK9VT0\\Users\\ysu\\Desktop\\tatilsepeti\\kampanya hata.txt"*/ values.AbsolutePath),
                Overwrite = true
            };

            Microsoft.SharePoint.Client.FileCollection files = folder.Files;
            Microsoft.SharePoint.Client.File           file  = files.Add(fci);

            cContext.Load(file);
            cContext.Load(files);
            cContext.ExecuteQuery();
        }
示例#9
0
文件: ConnectEcm.cs 项目: KKPBank/SLM
        public bool DeleteFile(string fileName, string folderName)
        {
            bool   result   = false;
            string siteUrl  = SLMConstant.Ecm.SiteUrl;      //http://ecm/dept/public
            string sitePath = SLMConstant.Ecm.SitePath;     ///dept/public/OBTDocument/
            string domain   = SLMConstant.Ecm.Domain;
            string username = SLMConstant.Ecm.Username;
            string password = SLMConstant.Ecm.Password;

            try
            {
                using (ToEcm.ClientContext clientContext = new ToEcm.ClientContext(siteUrl)
                {
                    Credentials = new NetworkCredential(username, password, domain)
                })
                {
                    string serverRelativeUrlOfFile = sitePath + folderName + "/" + fileName;

                    log.Info("Delete File Path " + serverRelativeUrlOfFile);

                    ToEcm.Web web = clientContext.Web;
                    clientContext.Load(web);

                    ToEcm.File file = web.GetFileByServerRelativeUrl(serverRelativeUrlOfFile);
                    clientContext.Load(file);
                    clientContext.ExecuteQuery();

                    if (file != null)
                    {
                        file.DeleteObject();
                        clientContext.ExecuteQuery();
                    }
                    result = true;

                    //Added By Pom 24/05/2016
                    //ลบ Folder ทิ้งในกรณีที่ไม่มี file เหลือใน Folder นั้น
                    try
                    {
                        log.Info("Start Delete Folder " + sitePath + folderName + "/");
                        ToEcm.Folder folder = web.GetFolderByServerRelativeUrl(sitePath + folderName + "/");
                        clientContext.Load(folder);
                        clientContext.ExecuteQuery();

                        if (folder != null)
                        {
                            ToEcm.FileCollection fileColl = folder.Files;
                            clientContext.Load(fileColl);
                            clientContext.ExecuteQuery();

                            log.Info("Files currently in folder " + folderName + " = " + fileColl.Count.ToString());

                            if (fileColl.Count == 0)
                            {
                                folder.DeleteObject();
                                clientContext.ExecuteQuery();
                                log.Info("Folder Deleted Successfully");
                            }
                        }
                        else
                        {
                            log.Info("Folder " + folderName + " is null");
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error DeleteFile : Cannot delete empty folder " + folderName + ", " + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Error DeleteFile : " + ex);
            }

            return(result);
        }