Exemplo n.º 1
0
        private bool ContainsObject(Object obj, System.Collections.ICollection list)
        {
            System.Collections.IEnumerator e = list.GetEnumerator();
            while (e.MoveNext())
            {
                Object o = e.Current;
                if (o is System.IO.FileInfo)
                {
                    System.IO.FileInfo f1 = (System.IO.FileInfo)o;
                    if (obj is System.IO.FileInfo)
                    {
                        System.IO.FileInfo f2 = (System.IO.FileInfo)obj;
                        if (f1.FullName == f2.FullName &&
                            f1.GetType() == f2.GetType())
                        {
                            return(true);
                        }
                    }
                }
                else if (o.Equals(obj))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        private static void UpdateSPList(ClientContext clientContext, DataTable dataTable, string fileName)
        {
            bool         isError         = true;
            string       strErrorMsg     = string.Empty;
            Int32        count           = 0;
            const string lstName         = "Files";
            const string lstColCreatedBy = "create";
            const string lstColType      = "typeof";
            const string lstColSize      = "Size";

            try
            {
                SP.List oList = clientContext.Web.Lists.GetByTitle(lstName);

                foreach (DataRow row in dataTable.Rows)
                {
                    if (count++ == 0)
                    {
                        continue;
                    }


                    string filee = row[0].ToString();

                    string             filename = filee.Split('\\').Last();
                    System.IO.FileInfo filesize = new System.IO.FileInfo(row[0].ToString());

                    long   size  = filesize.Length;
                    string exten = filesize.Extension;
                    Type   type  = filesize.GetType();
                    if ((size / 1048576.0) > 0 && (size / 1048576.0) < 15)
                    {
                        var fileCreationInformation = new FileCreationInformation();
                        fileCreationInformation.Content = System.IO.File.ReadAllBytes(row[0].ToString());


                        fileCreationInformation.Url = filename;
                        Microsoft.SharePoint.Client.File file = oList.RootFolder.Files.Add(fileCreationInformation);

                        clientContext.Load(file);
                        var item = file.ListItemAllFields;

                        item[lstColCreatedBy] = row[1].ToString();

                        item[lstColType] = exten;
                        item[lstColSize] = filesize.Length;
                        item.Update();

                        clientContext.ExecuteQuery();
                    }
                }

                isError = false;
            }
            catch (Exception e)
            {
                isError = true;
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (isError)
                {
                    //Logging
                }
            }
        }
Exemplo n.º 3
0
        private static void UpdateSPList(ClientContext clientContext, DataTable dataTable, string fileName)
        {
            bool         isError          = true;
            string       strErrorMsg      = string.Empty;
            Int32        count            = 0;
            const string lstName          = "UploadedFiles";
            const string lstColTitle      = "Title";
            const string lstColDepartment = "Department";
            const string lstColCreatedBy  = "CreatedBy";
            const string lstColType       = "Type";
            const string lstColSize       = "size";

            try
            {
                SP.List oList = clientContext.Web.Lists.GetByTitle(lstName);

                //FieldCollection fields = oList.Fields;
                //clientContext.Load(fields);
                //clientContext.ExecuteQuery();
                //foreach(SP.Field field in fields)
                //{
                //    Console.WriteLine(field.Title);
                //}
                foreach (DataRow row in dataTable.Rows)
                {
                    System.IO.FileInfo filesize = new System.IO.FileInfo(row[0].ToString());

                    long   size  = filesize.Length;
                    string exten = filesize.Extension;
                    Type   type  = filesize.GetType();
                    if ((size / 1048576.0) > 1 && (size / 1048576.0) < 15)
                    {
                        //    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                        //    ListItem oListItem = oList.AddItem(itemCreateInfo);
                        //oListItem.FieldValues[lstColTitle]= row[0].ToString();
                        //   oListItem[lstColTitle] = row[0].ToString();
                        //     oListItem.FieldValues[lstColDepartment] = row[1].ToString();
                        //  oListItem[lstColCreatedBy] = row[2];
                        //  oListItem[lstColType] = row[3];
                        //  oListItem[lstColSize] = row[2];
                        var fileCreationInformation = new FileCreationInformation();
                        fileCreationInformation.Content = System.IO.File.ReadAllBytes(@"C:\Users\vani reddy\documents\visual studio 2017\Projects\SharePointProject\SharePointProject\Screenshot (184).png");


                        fileCreationInformation.Url = row[0].ToString();
                        Microsoft.SharePoint.Client.File file = oList.RootFolder.Files.Add(fileCreationInformation);
                        clientContext.Load(file);
                        var item = file.ListItemAllFields;
                        item[lstColDepartment] = row[2].ToString();
                        item[lstColCreatedBy]  = row[1].ToString();
                        item[lstColType]       = exten;
                        item[lstColSize]       = filesize.Length;
                        item.Update();
                        clientContext.ExecuteQuery();
                        //      https://bytescout.com/products/developer/spreadsheetsdk/read-write-excel.html


                        count++;
                    }
                }

                isError = false;
            }
            catch (Exception e)
            {
                isError = true;
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (isError)
                {
                    //Logging
                }
            }
        }