Example #1
0
        /// <summary>
        /// </summary>
        private void bgWorker_btnGetKeys(object sender, DoWorkEventArgs e)
        {
            var msg  = "";
            var keys = new List <string>();

            try
            {
                SpConnectionManager conn = new SpConnectionManager(spUsername, spPassword, spDomain);
                conn.IsSpOnline = isSpOnline;
                conn.SiteUrl    = spSiteUrl;

                if (!SpComHelper.GetSitePropBagValues(conn, out keys, out msg))
                {
                    bgWorker.ReportProgress(0, "ERROR: " + msg);
                }
                else
                {
                    if (keys.Any())
                    {
                        bgWorker.ReportProgress(100, "Keys found:");
                        foreach (var key in keys.OrderBy(x => x.ToLower()))
                        {
                            bgWorker.ReportProgress(100, " * key: " + key);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                bgWorker.ReportProgress(0, "ERROR: " + ex.Message);
            }
        }
Example #2
0
        /// <summary>
        /// </summary>
        private void bgWorker_btnLoad(object sender, DoWorkEventArgs e)
        {
            var key = tbKey.Text.Trim();
            var val = "";
            var msg = "";

            try
            {
                SpConnectionManager conn = new SpConnectionManager(spUsername, spPassword, spDomain);
                conn.IsSpOnline = isSpOnline;
                conn.SiteUrl    = spSiteUrl;

                if (!SpComHelper.GetSitePropBagValue(conn, key, out val, out msg))
                {
                    bgWorker.ReportProgress(0, "ERROR: " + msg);
                }
            }
            catch (Exception ex)
            {
                bgWorker.ReportProgress(0, "ERROR: " + ex.Message);
            }

            e.Result = new List <object>()
            {
                val
            };
        }
Example #3
0
        /// <summary>
        /// </summary>
        private void bgWorker_btnSave(object sender, DoWorkEventArgs e)
        {
            var key = tbKey.Text.Trim();
            var val = tbValue.Text.Trim();
            var msg = "";

            try
            {
                SpConnectionManager conn = new SpConnectionManager(spUsername, spPassword, spDomain);
                conn.IsSpOnline = isSpOnline;
                conn.SiteUrl    = spSiteUrl;

                if (!SpComHelper.SetSitePropBagValue(conn, key, val, out msg))
                {
                    bgWorker.ReportProgress(0, "ERROR: " + msg);
                }
                else
                {
                    bgWorker.ReportProgress(0, "Property Bag Updated!");
                }
            }
            catch (Exception ex)
            {
                bgWorker.ReportProgress(0, "ERROR: " + ex.Message);
            }
        }
Example #4
0
        public static bool RenameSharePointFile(SpConnectionManager spConnection,
                                                string fileServerRelUrl,
                                                string newFileName,
                                                out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var file = ctx.Web.GetFileByServerRelativeUrl(fileServerRelUrl);
                    ctx.Load(file,
                             f => f.ListItemAllFields);
                    ctx.ExecuteQuery();

                    file.ListItemAllFields["FileLeafRef"] = GenUtil.CleanFilenameForSP(newFileName, "");
                    file.ListItemAllFields.Update();
                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #5
0
        /// <summary>
        /// </summary>
        public static bool GetSitePropBagValue(SpConnectionManager spConnection,
                                               string key,
                                               out string value,
                                               out string msg)
        {
            msg   = "";
            value = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var web      = ctx.Web;
                    var allProps = web.AllProperties;
                    ctx.Load(allProps);
                    ctx.ExecuteQuery();

                    if (allProps.FieldValues.ContainsKey(key))
                    {
                        value = allProps.FieldValues[key].SafeTrim();
                    }
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #6
0
        /// <summary>
        /// </summary>
        public static bool UndoCheckOutSPFile(SpConnectionManager spConnection,
                                              Guid listId,
                                              string fileServerRelUrl,
                                              out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var file = ctx.Web.GetFileByServerRelativeUrl(fileServerRelUrl);

                    ctx.Load(file, f => f.Name, f => f.ListItemAllFields, f => f.ServerRelativeUrl);
                    ctx.ExecuteQuery();

                    file.UndoCheckOut();
                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #7
0
        /// <summary>
        /// </summary>
        public static bool GetSitePropBagValues(SpConnectionManager spConnection,
                                                out List <string> keys,
                                                out string msg)
        {
            msg  = "";
            keys = new List <string>();

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var web      = ctx.Web;
                    var allProps = web.AllProperties;
                    ctx.Load(allProps);
                    ctx.ExecuteQuery();

                    foreach (var key in allProps.FieldValues.Keys)
                    {
                        keys.Add(key);
                    }
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #8
0
        /// <summary>
        /// </summary>
        public static bool CheckFolderExists(SpConnectionManager spConnection,
                                             string folderPath,
                                             out bool exists,
                                             out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    Folder folder = ctx.Web.GetFolderByServerRelativeUrl(folderPath);
                    ctx.Load(folder, x => x.Name, x => x.ServerRelativeUrl);
                    ctx.ExecuteQuery();

                    exists = true;
                }
            }
            catch (Exception ex)
            {
                // if folder doesn't exist it throws a "File Not Found" exception
                exists = false;

                if (!ex.Message.Equals("File Not Found."))
                {
                    // some other error
                    msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
                }
            }

            return(msg == "");
        }
Example #9
0
        /// <summary>
        /// </summary>
        public static bool CheckInSPFile(SpConnectionManager spConnection,
                                         Guid listId,
                                         string fileServerRelUrl,
                                         string comment,
                                         CheckinType checkinType,
                                         out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var file = ctx.Web.GetFileByServerRelativeUrl(fileServerRelUrl);

                    ctx.Load(file, f => f.Name, f => f.ListItemAllFields, f => f.ServerRelativeUrl);
                    ctx.ExecuteQuery();

                    file.CheckIn(GenUtil.SafeTrim(comment), checkinType);
                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #10
0
        /// <summary>
        /// </summary>
        public static bool GetSharePointFileFields(SpConnectionManager spConnection,
                                                   Guid listId,
                                                   string fileServerRelUrl,
                                                   out List <string> lstFieldNames,
                                                   out string msg)
        {
            msg           = "";
            lstFieldNames = new List <string>();

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var file = ctx.Web.GetFileByServerRelativeUrl(fileServerRelUrl);

                    ctx.Load(file, f => f.Name, f => f.ListItemAllFields, f => f.ServerRelativeUrl);
                    ctx.ExecuteQuery();

                    foreach (string fieldName in file.ListItemAllFields.FieldValues.Keys.OrderBy(x => x.Trim().ToLower()))
                    {
                        lstFieldNames.Add(fieldName);
                    }
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #11
0
        /// <summary>
        /// </summary>
        public static bool UpdateSharePointFileFields(SpConnectionManager spConnection,
                                                      Guid listId,
                                                      string fileServerRelUrl,
                                                      Hashtable ht,
                                                      out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var file = ctx.Web.GetFileByServerRelativeUrl(fileServerRelUrl);

                    ctx.Load(file, f => f.Name, f => f.ListItemAllFields, f => f.ServerRelativeUrl);
                    ctx.ExecuteQuery();

                    foreach (string key in ht.Keys)
                    {
                        file.ListItemAllFields[key] = ht[key].ToString();
                    }

                    file.ListItemAllFields.Update();
                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
        /// <summary>
        /// </summary>
        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string msg = "";

            byte[] buffer = null;

            var isSP = !spSiteUrl.IsNull();

            try
            {
                if (System.Configuration.ConfigurationManager.AppSettings["editorTextEncodingIsASCII"] == "1")
                {
                    buffer = System.Text.Encoding.ASCII.GetBytes(tbFileData.Text.Trim());
                }
                else
                {
                    buffer = System.Text.Encoding.UTF8.GetBytes(tbFileData.Text.Trim());
                }
            }
            catch (Exception ex)
            {
                msg = "ERROR converting to byte array: " + ex.Message;
            }

            if (msg.IsNull())
            {
                if (isSP)
                {
                    SpConnectionManager conn = new SpConnectionManager(spUsername, spPassword, spDomain);
                    conn.IsSpOnline = isSpOnline;
                    conn.SiteUrl    = spSiteUrl;

                    SpUploader      uploader = new SpUploader(conn);
                    ISpUploadResult res      = uploader.UploadFileToSharePoint(_filePath, buffer);

                    if (res.Success)
                    {
                        msg = "File Saved!";
                    }
                }
                else
                {
                    try
                    {
                        System.IO.File.WriteAllBytes(_filePath, buffer);
                        msg = "File Saved!";
                    }
                    catch (Exception ex)
                    {
                        msg = ex.Message;
                    }
                }
            }

            e.Result = new List <object>()
            {
                msg
            };
        }
Example #13
0
        public SpConnectionManager GetConnectionManager()
        {
            SpConnectionManager manager = new SpConnectionManager(_username, _password, _domain);

            manager.IsSpOnline = _isSharepointOnline;
            manager.SiteUrl    = Url;

            return(manager);
        }
Example #14
0
        public static bool GetSiteLists(SpConnectionManager spConnection, out List <SpLibrary> lstObjs, out string msg)
        {
            msg     = "";
            lstObjs = new List <SpLibrary>();

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var lists = ctx.Web.Lists;
                    ctx.Load(lists, l => l.Include(x => x.Title, x => x.Id, x => x.ContentTypes.Include(y => y.Name, y => y.Id)));

                    ctx.ExecuteQuery();

                    foreach (List list in lists)
                    {
                        bool match = false;
                        foreach (ContentType ct in list.ContentTypes)
                        {
                            if (ct.Id.ToString().StartsWith(DocumentLibraryContentTypeID))
                            {
                                match = true;
                                break;
                            }
                        }

                        if (match)
                        {
                            lstObjs.Add(new SpLibrary()
                            {
                                Id = list.Id, Title = list.Title
                            });
                        }
                    }

                    lstObjs = lstObjs.OrderBy(x => x.Title).ToList();
                }
            }
            catch (Exception ex)
            {
                //msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
                msg = ex.Message;
            }

            return(msg == "");
        }
Example #15
0
        /// <summary>
        /// </summary>
        public static bool MoveSPFile(SpConnectionManager spConnection,
                                      string fileServerRelUrl,
                                      string newFileServerRelUrl,
                                      bool overwrite,
                                      out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    File file = null;

                    if (!overwrite)
                    {
                        file = ctx.Web.GetFileByServerRelativeUrl(newFileServerRelUrl);

                        ctx.Load(file, f => f.Exists);
                        ctx.ExecuteQuery();

                        if (file.Exists)
                        {
                            msg = "File exists at destination.";
                            return(false);
                        }
                    }

                    file = ctx.Web.GetFileByServerRelativeUrl(fileServerRelUrl);

                    ctx.Load(file, f => f.Name, f => f.ListItemAllFields, f => f.ServerRelativeUrl);
                    ctx.ExecuteQuery();

                    file.MoveTo(newFileServerRelUrl, MoveOperations.Overwrite);

                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
        /// <summary>
        /// </summary>
        void bgWorkerLoadFields_DoWork(object sender, DoWorkEventArgs e)
        {
            // get field names for first file found, add to dropdownlist
            var           filePath      = _lstFilePaths[0];
            var           msg           = "";
            List <string> lstFieldNames = null;

            SpConnectionManager conn = new SpConnectionManager(spUsername, spPassword, spDomain);

            conn.IsSpOnline = isSpOnline;
            conn.SiteUrl    = spSiteUrl;

            SpComHelper.GetSharePointFileFields(conn, form1.curSPLocationObj.listId.Value, filePath, out lstFieldNames, out msg);

            e.Result = new List <object>()
            {
                msg, lstFieldNames
            };
        }
Example #17
0
        public static bool DeleteFolderFromSharePoint(SpConnectionManager spConnection,
                                                      string folderServerRelUrl,
                                                      out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var folder = ctx.Web.GetFolderByServerRelativeUrl(folderServerRelUrl);
                    folder.DeleteObject();

                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #18
0
        /// <summary>
        /// </summary>
        public static bool SetSitePropBagValue(SpConnectionManager spConnection,
                                               string key,
                                               string value,
                                               out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var web = ctx.Web;
                    web.AllProperties[key] = value;
                    web.Update();
                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #19
0
        public static bool CreateFolderInSharePoint(SpConnectionManager spConnection,
                                                    string folderName,
                                                    string parentFolderUrl,
                                                    out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var folder    = ctx.Web.GetFolderByServerRelativeUrl(parentFolderUrl);
                    var newFolder = folder.Folders.Add(folderName);

                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #20
0
        /// <summary>
        /// </summary>
        public static bool GetListAllFilesFolderLevel(SpConnectionManager spConnection,
                                                      Guid?listId,
                                                      string folderServerRelPath,
                                                      ref List <SpFileSystemItem> lstObjs,
                                                      out string msg)
        {
            // get all files (recursiveall) from a sub folder in a list
            // will be used for bulk operations (checkin, checkout, move, copy, update file fields, etc.)
            msg = "";

            if (lstObjs == null)
            {
                lstObjs = new List <SpFileSystemItem>();
            }

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var list = ctx.Web.Lists.GetById(listId.Value);

                    ListItemCollectionPosition pos = null;

                    while (true)
                    {
                        var cq = new CamlQuery();

                        cq.DatesInUtc = false;

                        var strViewFields = "<FieldRef Name='ID' /><FieldRef Name='FileLeafRef' /><FieldRef Name='FileDirRef' /><FieldRef Name='FileRef' /><FieldRef Name='FSObjType' />";
                        var strQuery      = "<Query></Query>";

                        var strViewXml = $"<View Scope='RecursiveAll'>{strQuery}<ViewFields>#{strViewFields}</ViewFields><RowLimit>{Consts.MAX_ROW_LIMIT}</RowLimit></View>";

                        cq.ListItemCollectionPosition = pos;
                        cq.ViewXml = strViewXml;
                        cq.FolderServerRelativeUrl = folderServerRelPath;

                        ListItemCollection lic = list.GetItems(cq);
                        ctx.Load(lic);
                        ctx.ExecuteQuery();

                        pos = lic.ListItemCollectionPosition;

                        foreach (ListItem item in lic)
                        {
                            var fsType = Convert.ToInt32(item["FSObjType"]);
                            if (fsType == 0)
                            {
                                var folderLevel = item["FileRef"].SafeTrim().ToCharArray().Count(x => x == '/');

                                lstObjs.Add(new SpFileSystemItem()
                                {
                                    treeNodeType = NodeType.FILE,
                                    name         = item["FileLeafRef"].SafeTrim(),
                                    url          = item["FileRef"].SafeTrim(),
                                    dtModified   = null,
                                    length       = 0,
                                    folderLevel  = folderLevel
                                });
                            }
                        }

                        if (pos == null)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #21
0
 public SpUploader(SpConnectionManager spConnection)
 {
     Connection = spConnection;
 }
Example #22
0
 public SpDownloader(SpConnectionManager spConnection)
 {
     _connection = spConnection;
 }
Example #23
0
        public static bool RenameSharePointFolder(SpConnectionManager spConnection,
                                                  Guid listId,
                                                  string folderServerRelUrl,
                                                  string newFolderName,
                                                  out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var oldFolderParentUrl = folderServerRelUrl.Substring(0, folderServerRelUrl.LastIndexOf('/'));
                    var oldFolderName      = folderServerRelUrl.Substring(folderServerRelUrl.LastIndexOf('/') + 1);

                    var list = ctx.Web.Lists.GetById(listId);

                    var query = new CamlQuery();
                    query.FolderServerRelativeUrl = oldFolderParentUrl;
                    query.ViewXml = "<View Scope=\"RecursiveAll\"> " +
                                    "<Query>" +
                                    "<Where>" +
                                    "<And>" +
                                    "<Eq>" +
                                    "<FieldRef Name=\"FSObjType\" />" +
                                    "<Value Type=\"Integer\">1</Value>" +
                                    "</Eq>" +
                                    "<Eq>" +
                                    "<FieldRef Name=\"FileLeafRef\"/>" +
                                    "<Value Type=\"Text\">" + oldFolderName + "</Value>" +
                                    "</Eq>" +
                                    "</And>" +
                                    "</Where>" +
                                    "</Query>" +
                                    "</View>";

                    var items = list.GetItems(query);

                    ctx.Load(items,
                             x => x.Include(
                                 y => y["Title"],
                                 y => y["FileLeafRef"]));

                    ctx.ExecuteQuery();

                    if (items.Count != 1)
                    {
                        throw new Exception("Folder not found: " + folderServerRelUrl);
                    }

                    items[0]["Title"]       = newFolderName;
                    items[0]["FileLeafRef"] = newFolderName;
                    items[0].Update();
                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Example #24
0
        /// <summary>
        /// </summary>


        /// <summary>
        /// </summary>
        public static bool GetListFoldersFilesRootLevel(SpConnectionManager spConnection,
                                                        Guid?listId,
                                                        int sortCol,
                                                        int rowLimit,
                                                        out string rootFolderPath,
                                                        out List <SpFileSystemItem> lstObjs,
                                                        out string msg)
        {
            msg            = "";
            lstObjs        = new List <SpFileSystemItem>();
            rootFolderPath = "";

            // make sure caml row limit is never more than 5000
            var camlRowLimit = rowLimit > Consts.MAX_ROW_LIMIT ? Consts.MAX_ROW_LIMIT : rowLimit;
            var i            = 0;

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var list = ctx.Web.Lists.GetById(listId.Value);

                    ctx.Load(list, x => x.Title);
                    ctx.Load(list.RootFolder, x => x.ServerRelativeUrl);
                    ctx.ExecuteQuery();

                    rootFolderPath = list.RootFolder.ServerRelativeUrl;

                    ListItemCollectionPosition pos = null;

                    while (true)
                    {
                        var cq = new CamlQuery();

                        cq.DatesInUtc = false;

                        var strViewFields = "<FieldRef Name='ID' /><FieldRef Name='FileLeafRef' /><FieldRef Name='FileDirRef' /><FieldRef Name='FileRef' /><FieldRef Name='FSObjType' /><FieldRef Name='Created' /><FieldRef Name='Modified' /><FieldRef Name='File_x0020_Size' />";
                        var strQuery      = "<Query></Query>";

                        var strViewXml = "<View Scope='All'>#QUERY#<ViewFields>#VIEWFIELDS#</ViewFields><RowLimit>#ROWLIMIT#</RowLimit></View>"
                                         .Replace("#ROWLIMIT", camlRowLimit.ToString())
                                         .Replace("#QUERY#", strQuery)
                                         .Replace("#VIEWFIELDS#", strViewFields);

                        cq.ListItemCollectionPosition = pos;
                        cq.ViewXml = strViewXml;
                        cq.FolderServerRelativeUrl = list.RootFolder.ServerRelativeUrl;
                        //cq.FolderServerRelativeUrl = "/sites/Zen20/EffLib/folder1"; // for sub folder

                        ListItemCollection lic = list.GetItems(cq);
                        ctx.Load(lic);
                        ctx.ExecuteQuery();

                        pos = lic.ListItemCollectionPosition;

                        foreach (ListItem item in lic)
                        {
                            i++;

                            var fsType = Convert.ToInt32(item["FSObjType"]);
                            if (fsType == 0)
                            {
                                var created  = (DateTime?)GenUtil.SafeToDateTime(item["Created"]);
                                var modified = (DateTime?)GenUtil.SafeToDateTime(item["Modified"]);

                                if (created.Value.Year == 1900)
                                {
                                    created = null;
                                }
                                if (modified.Value.Year == 1900)
                                {
                                    modified = null;
                                }
                                if (!modified.HasValue && created.HasValue)
                                {
                                    modified = created;
                                }

                                var filesize = (int?)GenUtil.SafeToNum(SafeGetFileSize(item));
                                if (filesize == -1)
                                {
                                    filesize = null;
                                }

                                lstObjs.Add(new SpFileSystemItem()
                                {
                                    treeNodeType = NodeType.FILE,
                                    name         = item["FileLeafRef"].SafeTrim(),
                                    url          = item["FileRef"].SafeTrim(),
                                    dtModified   = modified,
                                    length       = filesize
                                });
                            }
                            else
                            {
                                lstObjs.Add(new SpFileSystemItem()
                                {
                                    treeNodeType = NodeType.FOLDER,
                                    name         = item["FileLeafRef"].SafeTrim(),
                                    url          = item["FileRef"].SafeTrim()
                                });
                            }
                        }

                        if (pos == null || i >= rowLimit)
                        {
                            break;
                        }
                    }

                    if (sortCol == 0)
                    {
                        lstObjs = lstObjs.OrderBy(x => x.treeNodeType).ThenBy(x => x.name).ToList();
                    }
                    else if (sortCol == 1)
                    {
                        lstObjs = lstObjs.OrderBy(x => x.treeNodeType).ThenBy(x => x.length).ThenBy(x => x.name).ToList();
                    }
                    else if (sortCol == 2)
                    {
                        lstObjs = lstObjs.OrderBy(x => x.treeNodeType).ThenBy(x => x.dtModified).ThenBy(x => x.name).ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
        /// <summary>
        /// </summary>
        void bgWorkerSave_DoWork(object sender, DoWorkEventArgs e)
        {
            var errors_found = false;
            var msg          = "";

            var lstSubObjects = new List <SpFileSystemItem>();

            // add files to list
            foreach (string filePath in _lstFilePaths)
            {
                lstSubObjects.Add(new SpFileSystemItem()
                {
                    dtModified   = null,
                    folderLevel  = filePath.ToCharArray().Count(x => x == '/'),
                    treeNodeType = NodeType.FILE,
                    name         = filePath.Substring(filePath.LastIndexOf('/') + 1),
                    url          = filePath,
                    length       = 0
                });
            }

            // for any folders selected, get all the files in those folders, add to list for processing
            foreach (string curServRelFolderPath in _lstFolderPaths)
            {
                SpConnectionManager conn = new SpConnectionManager(spUsername, spPassword, spDomain);
                conn.IsSpOnline = isSpOnline;
                conn.SiteUrl    = spSiteUrl;

                if (!SpComHelper.GetListAllFilesFolderLevel(conn,
                                                            form1.curSPLocationObj.listId.Value, curServRelFolderPath, ref lstSubObjects, out msg))
                {
                    bgWorkerSave.ReportProgress(0, string.Format("Error getting folder sub objects, {0}: {1}", curServRelFolderPath, msg));
                    errors_found = errors_found || true;
                }
            }

            // process all files
            foreach (var curSubObject in lstSubObjects.OrderBy(x => x.folderLevel))
            {
                int i           = 0;
                var error_found = false;
                var filePath    = curSubObject.url;

                var htFieldVals = new Hashtable();

                while (i < gridFields.RowCount)
                {
                    var fieldName = GenUtil.SafeTrim(gridFields.Rows[i].Cells[0].Value);
                    var fieldVal  = GenUtil.SafeTrim(gridFields.Rows[i].Cells[1].Value);

                    if (!GenUtil.IsNull(fieldName))
                    {
                        htFieldVals[fieldName] = fieldVal;
                    }

                    i++;
                }

                if (htFieldVals.Count > 0)
                {
                    SpConnectionManager conn = new SpConnectionManager(spUsername, spPassword, spDomain);
                    conn.IsSpOnline = isSpOnline;
                    conn.SiteUrl    = spSiteUrl;

                    if (!SpComHelper.UpdateSharePointFileFields(conn, form1.curSPLocationObj.listId.Value, filePath, htFieldVals, out msg))
                    {
                        bgWorkerSave.ReportProgress(0, string.Format("Error updating file field data, {0}, invalid field name or value: {1}", filePath.Substring(filePath.LastIndexOf('/') + 1), msg));
                        error_found = true;
                    }
                    else
                    {
                        bgWorkerSave.ReportProgress(0, string.Format("File, {0}, Updated Successfully.", filePath.Substring(filePath.LastIndexOf('/') + 1)));
                    }

                    errors_found = errors_found || error_found;
                }
            }

            e.Result = new List <object>()
            {
                errors_found
            };
        }