Search This Blog

Friday, March 18, 2016

Passing Folder Name Get Data From Library

#region Get All File user wise permission in parent and child folder
        public List<NGOEntity> GetDocument()
        {

            List<NGOEntity> listRange = new List<NGOEntity>();
            var struserdomainId = GetReturnUserIDdomain();
            string[] userdomainId = struserdomainId.ToString().Split('|');
            if (userdomainId.Length > 0)
            {
                if (userdomainId[0].Length > 0 && userdomainId[1].Length > 0)
                {
                    userID = userdomainId[0].ToString().ToLower();
                    domainID = userdomainId[1].ToString().ToLower();
                }
            }
            string strCompName = GetReturnCompanyName();
            if (strCompName != "")
            {
                string[] arrCompany = strCompName.Split('/');
                //string CompanyName = string.Empty;
                //if (arrCompany.Length > 1)
                //{
                //    for (int k = 1; k < arrCompany.Length; k++)
                //    {
                //        CompanyName = arrCompany[k];
                //    }
                //}
                //else
                //{
                //    CompanyName = arrCompany[0];
                //}
                if (userID != "" && domainID != "")
                {
                    try
                    {
                        using (site = new SPSite(SPContext.Current.Site.Url))
                        {
                            using (spWeb = site.OpenWeb())
                            {
                                string libraryName = "NGODocument/"//used for
                                spWeb.AllowUnsafeUpdates = true;
                                SPList spListfol = spWeb.Lists.TryGetList("NGODocument");
                                SPQuery spQueryfol = new SPQuery();
                                //Getting the folder object from the list
                                SPFolder folder = spListfol.RootFolder.SubFolders[arrCompany[0]];
                                for (int k = 1; k < arrCompany.Length; k++)
                                {
                                    folder = GetNestedFolder(folder, arrCompany[k]);
                                }
                                //Set the Folder property
                               spQueryfol.Folder = folder;
                                SPListItemCollection items = spWeb.Lists[folder.ParentListId].GetItems(spQueryfol);
                                foreach (SPListItem spListItem in items)
                                {
                                    NGOEntity objNGOEntity = new NGOEntity();
                                    //SPFile spFile = spListItem.File;
                                    // Checking whether the item is a file or a folder //
                                    SPRoleAssignmentCollection assignPermissionFile = spListItem.RoleAssignments;
                                    foreach (SPRoleAssignment assignmentPerFileMember in assignPermissionFile)
                                    {
                                        string userdomaininFileName = string.Join(",", assignmentPerFileMember.Member);
                                        //string dogCsv3 = string.Join(",", assignment.Member.ID);
                                        bool VolidloginNameforFile = userdomaininFileName.Contains("\\");
                                        if (VolidloginNameforFile == true)
                                        {
                                            string[] groupuserforFile = userdomaininFileName.ToString().Split('\\');
                                            if (groupuserforFile[1].ToString() != "" && groupuserforFile[0].ToString() != "")
                                            {
                                                if (groupuserforFile[0].Contains("|"))
                                                {
                                                    string[] groupuserforFiledomain = groupuserforFile[0].ToString().Split('|');
                                                    strgroupuserFiledomain = groupuserforFiledomain[1].ToString();
                                                }
                                                else
                                                {
                                                    strgroupuserFiledomain = groupuserforFile[0].ToString();
                                                }
                                                if (groupuserforFile[1].ToString().ToLower() == userID.ToLower() && strgroupuserFiledomain.ToLower() == domainID.ToLower())
                                                {
                                                    if (spListItem.Folder != null)
                                                    {


                                                       // objNGOEntity.Company = CompanyName;
                                                        objNGOEntity.Company = spListItem.Folder.ParentFolder.ToString().Remove(0, libraryName.Length);
                                                        objNGOEntity.UniqueId = spListItem.UniqueId.ToString();
                                                        // objNGOEntity.CompanyId = spListItem.ID.ToString();
                                                        objNGOEntity.FolderName = spListItem.Name.Trim();
                                                        objNGOEntity.TimeStamp = spListItem.Folder.Item["Created"].ToString();
                                                        objNGOEntity.Version = spListItem.Folder.Item["Version"].ToString();
                                                        // objNGOEntity.Status = "Success";
                                                        listRange.Add(objNGOEntity);


                                                    }
                                                    else
                                                    {

                                                        objNGOEntity.Company = spListItem.File.ParentFolder.ToString().Remove(0, libraryName.Length);
                                                        objNGOEntity.UniqueId = spListItem.File.UniqueId.ToString();
                                                        //  objNGOEntity.CompanyId = spListItem.ID.ToString();
                                                        objNGOEntity.FileName = spListItem.File.Name.Trim();
                                                        objNGOEntity.FilePath = spWeb.Url.Trim() + @"/" + spListItem.File.Url.Trim();
                                                        objNGOEntity.TimeStamp = spListItem.File.Item["Created"].ToString();
                                                        objNGOEntity.Version = spListItem.File.Item["Version"].ToString();
                                                        // objNGOEntity.Status = "Success";
                                                        listRange.Add(objNGOEntity);

                                                    }
                                                }
                                            }
                                        }

                                    }
                                }
                                spWeb.AllowUnsafeUpdates = false;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        objErrorLog.WriteLog(ex.ToString());
                    }

                }
            }
            if (listRange.Count != 0)
            {

                JSonHelper helper = new JSonHelper();
                String jsonResult = helper.ConvertObjectToJSon(listRange);
                // Convert the sting to object
                listRange = null;
                listRange = helper.ConvertJSonToObject<List<NGOEntity>>(jsonResult);
                return listRange;

            }
            else
            {
                return listRange;
            }
        }
        #endregion


protected SPFolder GetNestedFolder(SPFolder spFolder, string strNestedFolderName)
        {
            spFolder = spFolder.SubFolders[strNestedFolderName];
            return spFolder;
        }



No comments:

Post a Comment