SharePoint 2013 provides a robust Representational State Transfer (REST) interface that allows any technology that supports standard REST capabilities to interact with SharePoint (sites, libraries, lists, etc). In addition to the built-in SharePoint REST API, you can create your own custom Windows Communication Foundation (WCF) REST services that are hosted in SharePoint. In this example, we'll explore the steps necessary to create a SharePoint-hosted WCF service with a REST interface that is deployed in a SharePoint solution (.wsp).
1-Create a solution
2-Map a ISAPI folder
3-Create SVCFile
Now :-
<%@ ServiceHost Language="C#" Debug="true"
Service="CDRParrentfolderWPermission.ISAPI.CDRParrentfolderWPermission, $SharePoint.Project.AssemblyFullName$"
CodeBehind="CDRParrentfolderWPermission.svc.cs"
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory,
Microsoft.SharePoint.Client.ServerRuntime, Version=15.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
Code IN SVC
using Microsoft.SharePoint.Client.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Activation;
using CDRParrentfolderWPermission.Model;
using Microsoft.SharePoint;
using SP = Microsoft.SharePoint.Client;
using System.Runtime.Remoting.Contexts;
using System.ServiceModel.Web;
using System.Net;
using Microsoft.SharePoint.Client;
using System.Runtime.Serialization.Json;
namespace CDRParrentfolderWPermission.ISAPI
{
// All My Services Url
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/Add_delUser //userID,domainID
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetCompanyWP //userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetDocument //:userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/DownloadFile //userID,domainID,fileid
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetDocumentSLF //userID,domainID, CompID
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetModifiedDocument //userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
//chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetDocumentCompanyWise
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetCompanyWOP -- not requred
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetCompamyDocument //userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class CDRParrentfolderWPermission : ICDRParrentfolderWPermission
{
CDRErrorLog objErrorLog = new CDRErrorLog();
string guidID = null;
string strgroupuserFolderdomain = string.Empty;
string strgroupuserFiledomain = string.Empty;
string userID = string.Empty;
string domainID = string.Empty;
string FileID = string.Empty;
string CompanyName = string.Empty;
string ModifiedDate = string.Empty;
string ServerDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string CompanyID = string.Empty;
string UniqueID = string.Empty;
SPWeb spWeb=null;
SPSite site=null;
SPList spList=null;
string LastSyncDate = string.Empty;
string Mode = string.Empty;
long valueModified;
long valueLastSyncDate = 0;
List<CDREntity> listRange1 = new List<CDREntity>();
CDREntity objCDREntity1 = new CDREntity();
string siteurl = "http://0179nitiv002tvs:29118/cdr";
#region Get all Folder of directory permission based (as Company )
public List<CDREntityFolderWithPerMission> GetCompanyWP()
{
var struserdomainId = GetReturnUserIDdomain();
string strLastSyncDate = GetReturnLastSyncDate();
if (strLastSyncDate != "")
{
valueLastSyncDate = Convert.ToInt64(Convert.ToDateTime(strLastSyncDate).ToString("yyyyMMddHHmmss"));
}
List<CDREntityFolderWithPerMission> listRangeCDREntityFolderWithPerMission = new List<CDREntityFolderWithPerMission>();
CDREntityFolderWithPerMission objCDREntityFolderWithPerMission = new CDREntityFolderWithPerMission();
List<string> CopmpanyLogodetails = new List<string>();
string libName = string.Empty;
try
{
if (struserdomainId!="")
{
//string strfolder = string.Empty
// Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteurl))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
spWeb.AllowUnsafeUpdates = true;
SPUser newUser = spWeb.EnsureUser(struserdomainId);
bool hasPermissions = spListItemCollection[i].DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
string FolderName = spListItemCollection[i].Name;
//string FolderName = spListItemCollection[i].Folder.ToString();
SPFile spCompFileItem = spListItemCollection[i].File;
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItemCollection[i].Folder.Item["Modified"]).ToString("yyyyMMddHHmmss"));
if (hasPermissions == true)
{
// Start Getting Company Logo
try
{
spWeb.AllowUnsafeUpdates = true;
spList = spWeb.Lists.TryGetList("CDRCompanyLogo");
SPQuery spQueryCopfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spList.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryCopfol.Folder = folder;
spQueryCopfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection Compitems = spList.GetItems(spQueryCopfol);
foreach (SPListItem spListCompItem in Compitems)
{
SPFile spCompFile = spListCompItem.File;
if (spCompFile.ToString() != null)
{
byte[] content = spCompFile.OpenBinary();
string Path = spWeb.Url.Trim() + @"/" + spCompFile.Url.Trim();
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("cdradmin", "cdr@dm!n@1234", "service");
byte[] obj = wc.DownloadData(Path);
String FileDataBaseTo64 = Convert.ToBase64String(obj);
objCDREntityFolderWithPerMission.LogoPath = Path;
objCDREntityFolderWithPerMission.LogoData = FileDataBaseTo64;
break;
}
else
{
// objCDREntityFolderWithPerMission.LogoPath = Path;
//objCDREntityFolderWithPerMission.LogoData = FileDataBaseTo64;
}
}
spWeb.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
// End Company Logo
if (strLastSyncDate != "")
{
if (valueLastSyncDate < valueModified)
{
objCDREntityFolderWithPerMission.Company = spListItemCollection[i].Name;
// objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].UniqueId.ToString();
objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].ID.ToString();
// objCDREntityFolderWithPerMission.Status = "Success";
objCDREntityFolderWithPerMission.Action = "Update";
objCDREntityFolderWithPerMission.LastSyncDate = ServerDate;
listRangeCDREntityFolderWithPerMission.Add(objCDREntityFolderWithPerMission);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityFolderWithPerMission);
// Convert the sting to object
listRangeCDREntityFolderWithPerMission = null;
listRangeCDREntityFolderWithPerMission = helper.ConvertJSonToObject<List<CDREntityFolderWithPerMission>>(jsonResult);
}
}
else
{
objCDREntityFolderWithPerMission.Company = spListItemCollection[i].Name;
// objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].UniqueId.ToString();
objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].ID.ToString();
// objCDREntityFolderWithPerMission.Status = "Success";
objCDREntityFolderWithPerMission.Action = "Insert";
objCDREntityFolderWithPerMission.LastSyncDate = ServerDate;
listRangeCDREntityFolderWithPerMission.Add(objCDREntityFolderWithPerMission);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityFolderWithPerMission);
// Convert the sting to object
listRangeCDREntityFolderWithPerMission = null;
listRangeCDREntityFolderWithPerMission = helper.ConvertJSonToObject<List<CDREntityFolderWithPerMission>>(jsonResult);
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
return listRangeCDREntityFolderWithPerMission;
}
if (listRangeCDREntityFolderWithPerMission.Count != 0)
{
return listRangeCDREntityFolderWithPerMission;
}
else
{
return listRangeCDREntityFolderWithPerMission;
}
}
#endregion
#region Get All File user wise permission in parent and child folder
public List<CDREntity> GetDocument()
{
List<CDREntity> listRange = new List<CDREntity>();
CDREntity objCDREntity = new CDREntity();
var struserdomainId = GetReturnUserIDdomain();
string strLastSyncDate = GetReturnLastSyncDate();
if (strLastSyncDate != "")
{
valueLastSyncDate = Convert.ToInt64(Convert.ToDateTime(strLastSyncDate).ToString("yyyyMMddHHmmss"));
}
string libName = string.Empty;
try
{
if (struserdomainId!="")
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteurl))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
spWeb.AllowUnsafeUpdates = true;
SPUser newUser = spWeb.EnsureUser(struserdomainId);
bool hasPermissions = spListItemCollection[i].DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
string FolderName = spListItemCollection[i].Name;
//string FolderName = spListItemCollection[i].Folder.ToString();
SPFile spCompFileItem = spListItemCollection[i].File;
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItemCollection[i].Folder.Item["Modified"]).ToString("yyyyMMddHHmmss"));
if (hasPermissions == true)
{
try
{
string libraryName = "CDRDocument/"; //used for
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
spQueryfol.Query = @"<Where><Eq><FieldRef Name='Approval_Status'/><Value Type='Text'>Approved</Value></Eq></Where>";
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
// string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
bool hasPermissionsfile = spListItem.DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
if (hasPermissionsfile == true)
{
if (strLastSyncDate != "")
{
if (Convert.ToDateTime(spListItem.File.Item["Visible Date"]).ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
{
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItem.File.Item["Modified"]).ToString("yyyyMMddHHmmss"));
if (valueLastSyncDate < valueModified)
{
objCDREntity.Company = spFile.ParentFolder.ToString().Remove(0, libraryName.Length);
objCDREntity.UniqueId = spFile.UniqueId.ToString();
//objCDREntity.CompanyId = spListItem.ID.ToString();
objCDREntity.FileName = spFile.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// objCDREntity.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntity.Version = spFile.MajorVersion.ToString();
objCDREntity.LastSyncDate = ServerDate;
objCDREntity.Action = "Update";
//objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDREntity>>(jsonResult);
}
}
}
else
{
if (Convert.ToDateTime(spListItem.File.Item["Visible Date"]).ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
{
objCDREntity.Company = spFile.ParentFolder.ToString().Remove(0, libraryName.Length);
objCDREntity.UniqueId = spFile.UniqueId.ToString();
//objCDREntity.CompanyId = spListItem.ID.ToString();
objCDREntity.FileName = spFile.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// objCDREntity.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntity.Version = spFile.MajorVersion.ToString();
objCDREntity.LastSyncDate = ServerDate;
objCDREntity.Action = "Insert";
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDREntity>>(jsonResult);
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
// }
if (listRange.Count != 0)
{
return listRange;
}
else
{
return listRange;
}
}
#endregion
#region Get Downlaods File Name In In ToBase64String On Basis of Token Id and Guid Id of document
public List<CDREntityDownloadsFile> DownloadFile()
{
var struserdomainId = GetReturnUserIDdomain();
// string strLastSyncDate = GetReturnLastSyncDate();
//if (strLastSyncDate != "")
//{
// valueLastSyncDate = Convert.ToInt64(Convert.ToDateTime(strLastSyncDate).ToString("yyyyMMddHHmmss"));
//}
FileID = GetReturnFileID();
List<CDREntityDownloadsFile> listRangeCDREntityDownloadsFile = new List<CDREntityDownloadsFile>();
CDREntityDownloadsFile objCDREntityDownloadsFile = new CDREntityDownloadsFile();
string libName = string.Empty;
try
{
if (struserdomainId != "" && FileID != "")
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteurl))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
spWeb.AllowUnsafeUpdates = true;
SPUser newUser = spWeb.EnsureUser(struserdomainId);
bool hasPermissions = spListItemCollection[i].DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
string FolderName = spListItemCollection[i].Name;
//string FolderName = spListItemCollection[i].Folder.ToString();
SPFile spCompFileItem = spListItemCollection[i].File;
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItemCollection[i].Folder.Item["Modified"]).ToString("yyyyMMddHHmmss"));
if (hasPermissions == true)
{
try
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
spQueryfol.Query = @"<Where><Eq><FieldRef Name='UniqueId'/><Value Type='Text'>" + FileID + @"</Value></Eq></Where>";
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
SPFile spFile = spListItem.File;
bool hasPermissionsfile = spListItem.DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
if (hasPermissionsfile == true)
{
string FolderName1 = spListItem.Name;
byte[] content = spFile.OpenBinary();
if (spFile.UniqueId.ToString().ToLower() == FileID.ToLower())
{
string Path = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("cdradmin", "cdr@dm!n@1234", "service");
byte[] obj = wc.DownloadData(Path);
String FileDataBaseTo64 = Convert.ToBase64String(obj);
////sends the request, converts response to s stream
//HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Path);
//webRequest.UseDefaultCredentials = true;
//webRequest.PreAuthenticate = true;
//webRequest.Credentials = CredentialCache.DefaultCredentials;
//HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
//Stream reqStr = webResponse.GetResponseStream();
////reads the response stream
//StreamReader sr = new StreamReader(reqStr, System.Text.Encoding.UTF8);
//string content1 = String.Empty;
//content1 = sr.ReadToEnd();
objCDREntityDownloadsFile.fileid = FileID;
objCDREntityDownloadsFile.FilePath = Path;
objCDREntityDownloadsFile.FileData = FileDataBaseTo64;
listRangeCDREntityDownloadsFile.Add(objCDREntityDownloadsFile);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityDownloadsFile);
// Convert the sting to object
listRangeCDREntityDownloadsFile = null;
listRangeCDREntityDownloadsFile = helper.ConvertJSonToObject<List<CDREntityDownloadsFile>>(jsonResult);
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRangeCDREntityDownloadsFile.Count != 0)
{
return listRangeCDREntityDownloadsFile;
}
else
{
return listRangeCDREntityDownloadsFile;
}
}
#endregion
#region Add && delete User in user list
public List<CDREntityAdd_DelUser> Add_delUser()
{
List<CDREntityAdd_DelUser> listRangeCDREntityAdd_DelUser = new List<CDREntityAdd_DelUser>();
CDREntityAdd_DelUser objCDREntityAdd_DelUser = new CDREntityAdd_DelUser();
var struserdomainId = GetReturnUserIDdomain();
var strMode = GetReturnOpartionMode();
string[] userdomainId = struserdomainId.ToString().Split('|');
if (userdomainId.Length > 0 && strMode != "")
{
Mode = strMode;
if (userdomainId[0].Length > 0 && userdomainId[1].Length > 0)
{
userID = userdomainId[0];
domainID = userdomainId[1];
if (Mode.ToLower() == "add")
{
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList oList = web.Lists["CDRConfiguration"];
if (oList != null)
{
//Add a new item in the List
SPListItem item = oList.Items.Add();
item["Title"] = userID;
item["UserId"] = userID;
item["DomainID"] = domainID;
item["IsActive"] = 1;
item.Update();
objCDREntityAdd_DelUser.Status = "Success";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
objCDREntityAdd_DelUser.Status = "Failed";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
}
else if (Mode.ToLower() == "del")
{
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// create the site object
using (SPSite site = new SPSite(siteID))
{
// create the web object
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='UserId'/><Value Type='Text'>" + userID + @"</Value></Eq></Where>";
// create the list object
SPList oList = web.Lists["CDRConfiguration"];
//create the item collection object
SPListItemCollection itemcollection = oList.GetItems(query);
foreach (SPListItem item in itemcollection)
{
SPListItem itemToUpdate = oList.GetItemById(item.ID);
itemToUpdate["IsActive"] = 0;
// updating the data
itemToUpdate.Update();
objCDREntityAdd_DelUser.Status = "Success";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
objCDREntityAdd_DelUser.Status = "Failed";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
}
else
{
objCDREntityAdd_DelUser.Status = "Failed";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
}
}
return listRangeCDREntityAdd_DelUser;
}
#endregion
#region Get All File user wise permission in Only Second Lavel Of folder( Root Folder and Child Folder)
public List<CDREntitySLF> GetDocumentSLF()
{
var struserdomainId = GetReturnUserIDdomain();
CompanyID = GetReturnCompanyID();
if (CompanyID != "")
{
// get Company Name
try
{
///Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteurl))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists["CDRDocument"];
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + CompanyID + @"</Value></Eq></Where>";
// query.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
//query.RowLimit = 1;
SPListItemCollection items = spList.GetItems(query);
if (items.Count > 0)
{
SPListItem _item = items[0];
CompanyName = _item["Title"].ToString();
}
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
//
}
List<CDREntitySLF> listRangeCDREntitySLF = new List<CDREntitySLF>();
CDREntitySLF objCDREntitySLF = new CDREntitySLF();
string libName = string.Empty;
try
{
if (struserdomainId != "" && CompanyName != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
if (CompanyName == FolderName)
{
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
//string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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())
{
string name = spListItem["AccessLevel"].ToString();
if (name == "Y")
{
objCDREntitySLF.Company = spFile.ParentFolder.ToString();
objCDREntitySLF.UniqueId = spFile.UniqueId.ToString();
objCDREntitySLF.FileName = spFile.Name.Trim();
objCDREntitySLF.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
objCDREntitySLF.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntitySLF.Version = spFile.MajorVersion.ToString();
objCDREntitySLF.Status = "Success";
listRangeCDREntitySLF.Add(objCDREntitySLF);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntitySLF);
// Convert the sting to object
listRangeCDREntitySLF = null;
listRangeCDREntitySLF = helper.ConvertJSonToObject<List<CDREntitySLF>>(jsonResult);
}
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
//
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRangeCDREntitySLF.Count != 0)
{
return listRangeCDREntitySLF;
}
else
{
return listRangeCDREntitySLF;
}
}
#endregion
#region Get All File user wise permission in parent and child folder Company Wise
public List<CDREntity> GetDocumentCompanyWise()
{
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 strModifiedDate = GetReturnModifiedDate();
if (UniqueID != "")
{
// get Company Name
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists["CDRDocument"];
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + UniqueID + @"</Value></Eq></Where>";
// query.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
//query.RowLimit = 1;
SPListItemCollection items = spList.GetItems(query);
if (items.Count > 0)
{
SPListItem _item = items[0];
CompanyName = _item["Name"].ToString();
}
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
//
}
List<CDREntity> listRange = new List<CDREntity>();
CDREntity objCDREntity = new CDREntity();
string libName = string.Empty;
try
{
if (userID != "" && domainID != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
if (FolderName.ToLower() == CompanyName.ToLower())
{
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString().ToLower();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString().ToLower();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
// string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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())
{
objCDREntity.Company = spFile.ParentFolder.ToString();
//objCDREntity.CompanyId = spListItemCollection[i].ID.ToString();
objCDREntity.UniqueId = spFile.UniqueId.ToString();
objCDREntity.FileName = spFile.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// objCDREntity.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntity.Version = spFile.MajorVersion.ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDREntity>>(jsonResult);
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
//folder Loop
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRange.Count != 0)
{
return listRange;
}
else
{
return listRange;
}
}
#endregion
#region Get All File user wise permission in based on Company Name
public List<CDREntity> GetCompamyDocument()
{
List<CDREntity> listRange = new List<CDREntity>();
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())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
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)
{
CDREntity objCDREntity = new CDREntity();
//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)
{
objCDREntity.Company = CompanyName;
objCDREntity.UniqueId = spListItem.UniqueId.ToString();
// objCDREntity.CompanyId = spListItem.ID.ToString();
// objCDREntity.FolderName = spListItem.Name.Trim();
// objCDREntity.TimeStamp = spListItem.Folder.Item["Created"].ToString();
objCDREntity.Version = spListItem.Folder.Item["Version"].ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
}
else
{
objCDREntity.Company = CompanyName;
objCDREntity.UniqueId = spListItem.File.UniqueId.ToString();
// objCDREntity.CompanyId = spListItem.ID.ToString();
objCDREntity.FileName = spListItem.File.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spListItem.File.Url.Trim();
// objCDREntity.TimeStamp = spListItem.File.Item["Created"].ToString();
objCDREntity.Version = spListItem.File.Item["Version"].ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
}
}
}
}
}
}
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<CDREntity>>(jsonResult);
return listRange;
}
else
{
return listRange;
}
}
#endregion
#region Return Header Param userId |domain|FileId|Mode|CompanyID
public string GetReturnUserIDdomain()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strParam = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["UserID"] != null)
{
userID = headers["UserID"];
}
if (headers["domainID"] != null)
{
domainID = headers["domainID"];
}
break;
}
strParam = domainID + "\\" + userID;
return strParam;
}
public string GetReturnFileID()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strParamFileID = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["FileID"] != null)
{
FileID = headers["FileID"];
}
break;
}
strParamFileID = FileID;
return strParamFileID;
}
public string GetReturnOpartionMode()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strParamMode = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["Mode"] != null)
{
Mode = headers["Mode"];
}
break;
}
strParamMode = Mode;
return strParamMode;
}
public string GetReturnCompanyID()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strCompanyID = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["CompID"] != null)
{
CompanyID = headers["CompID"];
}
break;
}
strCompanyID = CompanyID;
return strCompanyID;
}
public string GetReturnCompanyName()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strCompanyName = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["CompanyName"] != null)
{
CompanyName = headers["CompanyName"];
}
break;
}
strCompanyName = CompanyName;
return strCompanyName;
}
public string GetReturnLastSyncDate()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strLastSyncDate = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["LastSyncDate"] != null)
{
LastSyncDate = headers["LastSyncDate"];
}
break;
}
strLastSyncDate = LastSyncDate;
return strLastSyncDate;
}
public string GetReturnModifiedDate()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strModifiedDate = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["ModifiedDate"] != null)
{
ModifiedDate = headers["ModifiedDate"];
}
break;
}
strModifiedDate = ModifiedDate;
return strModifiedDate;
}
public string GetReturnCompanyIDFromCDRDocumentList()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strUniqueID = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["UniqueID"] != null)
{
UniqueID = headers["UniqueID"];
}
break;
}
strUniqueID = UniqueID;
return strUniqueID;
}
#endregion
protected SPFolder GetNestedFolder(SPFolder spFolder, string strNestedFolderName)
{
spFolder = spFolder.SubFolders[strNestedFolderName];
return spFolder;
}
#region Get All File user wise permission in parent and child folder
public List<CDRModifiedEntity> GetModifiedDocument()
{
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 strModifiedDate = GetReturnModifiedDate();
List<CDRModifiedEntity> listRange = new List<CDRModifiedEntity>();
CDRModifiedEntity objCDRModifiedEntity = new CDRModifiedEntity();
string libName = string.Empty;
try
{
if (userID != "" && domainID != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
// Guid siteID = "https://stageone.motherson.com/sites/cdr";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString().ToLower();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString().ToLower();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
// string SPquery1 = @"<Where><Ge><FieldRef Name='Modified'IncludeTimeValue='TRUE'/><Value Type='DateTime'>2016-03-08T03:39:00Z</Value></Ge></Where>";
// string SPquery = @"<Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime'>2016-03-07 3:39</Value></Geq></Where>";
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
// spQueryfol.Query = SPquery1;
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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())
{
Double DiferenceDate = TimeDifferenceInMinutes(Convert.ToDateTime(spFile.Item["Modified"]), Convert.ToDateTime(strModifiedDate));
//objCDRModifiedEntity.Company = spFile.ParentFolder.ToString();
//objCDRModifiedEntity.UniqueId = spFile.UniqueId.ToString();
//objCDREntity.CompanyId = spListItem.ID.ToString();
if (DiferenceDate > 0)
{
objCDRModifiedEntity.FileName = spFile.Name.Trim();
objCDRModifiedEntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
objCDRModifiedEntity.Modified = spFile.Item["Modified"].ToString();
// objCDREntity.Status = "Success";
// objCDRModifiedEntity.Version = spFile.Item["Version"].ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDRModifiedEntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDRModifiedEntity>>(jsonResult);
}
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRange.Count != 0)
{
return listRange;
}
else
{
return listRange;
}
}
#endregion
public static double TimeDifferenceInMinutes(DateTime dateone, DateTime datetwo)
{
var duration = dateone - datetwo;
return duration.TotalMinutes;
}
}
}
4- Used Entity Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDRParrentfolderWPermission.Model
{
public class CDREntity
{
//public String CompanyId { get; set; }
//public String FolderName { get; set; }
public String FileName { get; set; }
public String FilePath { get; set; }
public String Company { get; set; }
// public String TimeStamp { get; set; }
public String Version { get; set; }
public String UniqueId { get; set; }
public String Action { get; set; }
public String LastSyncDate { get; set; }
// public string Status { get; set; }
}
public class CDREntityFolderWithoutPerMission
{
public String UniqueId { get; set; }
public String Company { get; set; }
public string Status { get; set; }
}
public class CDREntityFolderWithPerMission
{
public String UniqueId { get; set; }
public String Company { get; set; }
public String LogoPath { get; set; }
public string LogoData { get; set; }
public String LastSyncDate { get; set; }
public String Action { get; set; }
// public string Status { get; set; }
}
public class CDREntitySLF
{
public String UniqueId { get; set; }
public String FileName { get; set; }
public String FilePath { get; set; }
public String Company { get; set; }
public String TimeStamp { get; set; }
public String Version { get; set; }
public string Status { get; set; }
//public string FolderLavel { get; set; }
}
public class CDREntityDownloadsFile
{
public String fileid { get; set; }
public String FilePath { get; set; }
public string FileData { get; set; }
}
public class CDREntityAdd_DelUser
{
public string Status { get; set; }
}
public class CDRModifiedEntity
{
//public String CompanyId { get; set; }
//public String FolderName { get; set; }
public String FileName { get; set; }
public String FilePath { get; set; }
// public String Company { get; set; }
public String Modified { get; set; }
// public String Version { get; set; }
// public String UniqueId { get; set; }
// public string Status { get; set; }
}
}
5- Log File Class
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDRParrentfolderWPermission.Model
{
public class CDRErrorLog
{
public void WriteLog(string strLog)
{
System.IO.StreamWriter log;
FileStream fileStream = null;
DirectoryInfo logDirInfo = null;
FileInfo logFileInfo;
//string Folderpath = WebConfigurationManager.AppSettings["ErrorFolderpath"].ToString();
string logFilePath = "C:\\Logs\\";
// string logFilePath = Folderpath;
logFilePath = logFilePath + "CDRParrentfolderWPermission" + "_" + System.DateTime.Today.ToString("dd-MM-yyyy") + "." + "txt";
logFileInfo = new FileInfo(logFilePath);
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
if (!logDirInfo.Exists) logDirInfo.Create();
if (!logFileInfo.Exists)
{
fileStream = logFileInfo.Create();
}
else
{
fileStream = new FileStream(logFilePath, FileMode.Append);
}
log = new StreamWriter(fileStream);
log.WriteLine("*******************************" + DateTime.Now + "********************************");
log.WriteLine(strLog);
log.Close();
}
}
}
6- Used JSON Serilization
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
namespace CDRParrentfolderWPermission.Model
{
public class JSonHelper
{
public string ConvertObjectToJSon<T>(T obj)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, obj);
string jsonString = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
return jsonString;
}
public T ConvertJSonToObject<T>(string jsonString)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T obj = (T)serializer.ReadObject(ms);
return obj;
}
}
}
1-Create a solution
2-Map a ISAPI folder
3-Create SVCFile
Now :-
<%@ ServiceHost Language="C#" Debug="true"
Service="CDRParrentfolderWPermission.ISAPI.CDRParrentfolderWPermission, $SharePoint.Project.AssemblyFullName$"
CodeBehind="CDRParrentfolderWPermission.svc.cs"
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory,
Microsoft.SharePoint.Client.ServerRuntime, Version=15.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
Code IN SVC
using Microsoft.SharePoint.Client.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Activation;
using CDRParrentfolderWPermission.Model;
using Microsoft.SharePoint;
using SP = Microsoft.SharePoint.Client;
using System.Runtime.Remoting.Contexts;
using System.ServiceModel.Web;
using System.Net;
using Microsoft.SharePoint.Client;
using System.Runtime.Serialization.Json;
namespace CDRParrentfolderWPermission.ISAPI
{
// All My Services Url
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/Add_delUser //userID,domainID
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetCompanyWP //userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetDocument //:userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/DownloadFile //userID,domainID,fileid
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetDocumentSLF //userID,domainID, CompID
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetModifiedDocument //userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
//chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetDocumentCompanyWise
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetCompanyWOP -- not requred
//http://0179nitiv002tvs:29118/_vti_bin/CDRParrentfolderWPermission.svc/GetCompamyDocument //userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class CDRParrentfolderWPermission : ICDRParrentfolderWPermission
{
CDRErrorLog objErrorLog = new CDRErrorLog();
string guidID = null;
string strgroupuserFolderdomain = string.Empty;
string strgroupuserFiledomain = string.Empty;
string userID = string.Empty;
string domainID = string.Empty;
string FileID = string.Empty;
string CompanyName = string.Empty;
string ModifiedDate = string.Empty;
string ServerDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string CompanyID = string.Empty;
string UniqueID = string.Empty;
SPWeb spWeb=null;
SPSite site=null;
SPList spList=null;
string LastSyncDate = string.Empty;
string Mode = string.Empty;
long valueModified;
long valueLastSyncDate = 0;
List<CDREntity> listRange1 = new List<CDREntity>();
CDREntity objCDREntity1 = new CDREntity();
string siteurl = "http://0179nitiv002tvs:29118/cdr";
#region Get all Folder of directory permission based (as Company )
public List<CDREntityFolderWithPerMission> GetCompanyWP()
{
var struserdomainId = GetReturnUserIDdomain();
string strLastSyncDate = GetReturnLastSyncDate();
if (strLastSyncDate != "")
{
valueLastSyncDate = Convert.ToInt64(Convert.ToDateTime(strLastSyncDate).ToString("yyyyMMddHHmmss"));
}
List<CDREntityFolderWithPerMission> listRangeCDREntityFolderWithPerMission = new List<CDREntityFolderWithPerMission>();
CDREntityFolderWithPerMission objCDREntityFolderWithPerMission = new CDREntityFolderWithPerMission();
List<string> CopmpanyLogodetails = new List<string>();
string libName = string.Empty;
try
{
if (struserdomainId!="")
{
//string strfolder = string.Empty
// Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteurl))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
spWeb.AllowUnsafeUpdates = true;
SPUser newUser = spWeb.EnsureUser(struserdomainId);
bool hasPermissions = spListItemCollection[i].DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
string FolderName = spListItemCollection[i].Name;
//string FolderName = spListItemCollection[i].Folder.ToString();
SPFile spCompFileItem = spListItemCollection[i].File;
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItemCollection[i].Folder.Item["Modified"]).ToString("yyyyMMddHHmmss"));
if (hasPermissions == true)
{
// Start Getting Company Logo
try
{
spWeb.AllowUnsafeUpdates = true;
spList = spWeb.Lists.TryGetList("CDRCompanyLogo");
SPQuery spQueryCopfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spList.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryCopfol.Folder = folder;
spQueryCopfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection Compitems = spList.GetItems(spQueryCopfol);
foreach (SPListItem spListCompItem in Compitems)
{
SPFile spCompFile = spListCompItem.File;
if (spCompFile.ToString() != null)
{
byte[] content = spCompFile.OpenBinary();
string Path = spWeb.Url.Trim() + @"/" + spCompFile.Url.Trim();
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("cdradmin", "cdr@dm!n@1234", "service");
byte[] obj = wc.DownloadData(Path);
String FileDataBaseTo64 = Convert.ToBase64String(obj);
objCDREntityFolderWithPerMission.LogoPath = Path;
objCDREntityFolderWithPerMission.LogoData = FileDataBaseTo64;
break;
}
else
{
// objCDREntityFolderWithPerMission.LogoPath = Path;
//objCDREntityFolderWithPerMission.LogoData = FileDataBaseTo64;
}
}
spWeb.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
// End Company Logo
if (strLastSyncDate != "")
{
if (valueLastSyncDate < valueModified)
{
objCDREntityFolderWithPerMission.Company = spListItemCollection[i].Name;
// objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].UniqueId.ToString();
objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].ID.ToString();
// objCDREntityFolderWithPerMission.Status = "Success";
objCDREntityFolderWithPerMission.Action = "Update";
objCDREntityFolderWithPerMission.LastSyncDate = ServerDate;
listRangeCDREntityFolderWithPerMission.Add(objCDREntityFolderWithPerMission);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityFolderWithPerMission);
// Convert the sting to object
listRangeCDREntityFolderWithPerMission = null;
listRangeCDREntityFolderWithPerMission = helper.ConvertJSonToObject<List<CDREntityFolderWithPerMission>>(jsonResult);
}
}
else
{
objCDREntityFolderWithPerMission.Company = spListItemCollection[i].Name;
// objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].UniqueId.ToString();
objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].ID.ToString();
// objCDREntityFolderWithPerMission.Status = "Success";
objCDREntityFolderWithPerMission.Action = "Insert";
objCDREntityFolderWithPerMission.LastSyncDate = ServerDate;
listRangeCDREntityFolderWithPerMission.Add(objCDREntityFolderWithPerMission);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityFolderWithPerMission);
// Convert the sting to object
listRangeCDREntityFolderWithPerMission = null;
listRangeCDREntityFolderWithPerMission = helper.ConvertJSonToObject<List<CDREntityFolderWithPerMission>>(jsonResult);
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
return listRangeCDREntityFolderWithPerMission;
}
if (listRangeCDREntityFolderWithPerMission.Count != 0)
{
return listRangeCDREntityFolderWithPerMission;
}
else
{
return listRangeCDREntityFolderWithPerMission;
}
}
#endregion
#region Get All File user wise permission in parent and child folder
public List<CDREntity> GetDocument()
{
List<CDREntity> listRange = new List<CDREntity>();
CDREntity objCDREntity = new CDREntity();
var struserdomainId = GetReturnUserIDdomain();
string strLastSyncDate = GetReturnLastSyncDate();
if (strLastSyncDate != "")
{
valueLastSyncDate = Convert.ToInt64(Convert.ToDateTime(strLastSyncDate).ToString("yyyyMMddHHmmss"));
}
string libName = string.Empty;
try
{
if (struserdomainId!="")
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteurl))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
spWeb.AllowUnsafeUpdates = true;
SPUser newUser = spWeb.EnsureUser(struserdomainId);
bool hasPermissions = spListItemCollection[i].DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
string FolderName = spListItemCollection[i].Name;
//string FolderName = spListItemCollection[i].Folder.ToString();
SPFile spCompFileItem = spListItemCollection[i].File;
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItemCollection[i].Folder.Item["Modified"]).ToString("yyyyMMddHHmmss"));
if (hasPermissions == true)
{
try
{
string libraryName = "CDRDocument/"; //used for
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
spQueryfol.Query = @"<Where><Eq><FieldRef Name='Approval_Status'/><Value Type='Text'>Approved</Value></Eq></Where>";
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
// string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
bool hasPermissionsfile = spListItem.DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
if (hasPermissionsfile == true)
{
if (strLastSyncDate != "")
{
if (Convert.ToDateTime(spListItem.File.Item["Visible Date"]).ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
{
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItem.File.Item["Modified"]).ToString("yyyyMMddHHmmss"));
if (valueLastSyncDate < valueModified)
{
objCDREntity.Company = spFile.ParentFolder.ToString().Remove(0, libraryName.Length);
objCDREntity.UniqueId = spFile.UniqueId.ToString();
//objCDREntity.CompanyId = spListItem.ID.ToString();
objCDREntity.FileName = spFile.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// objCDREntity.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntity.Version = spFile.MajorVersion.ToString();
objCDREntity.LastSyncDate = ServerDate;
objCDREntity.Action = "Update";
//objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDREntity>>(jsonResult);
}
}
}
else
{
if (Convert.ToDateTime(spListItem.File.Item["Visible Date"]).ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
{
objCDREntity.Company = spFile.ParentFolder.ToString().Remove(0, libraryName.Length);
objCDREntity.UniqueId = spFile.UniqueId.ToString();
//objCDREntity.CompanyId = spListItem.ID.ToString();
objCDREntity.FileName = spFile.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// objCDREntity.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntity.Version = spFile.MajorVersion.ToString();
objCDREntity.LastSyncDate = ServerDate;
objCDREntity.Action = "Insert";
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDREntity>>(jsonResult);
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
// }
if (listRange.Count != 0)
{
return listRange;
}
else
{
return listRange;
}
}
#endregion
#region Get Downlaods File Name In In ToBase64String On Basis of Token Id and Guid Id of document
public List<CDREntityDownloadsFile> DownloadFile()
{
var struserdomainId = GetReturnUserIDdomain();
// string strLastSyncDate = GetReturnLastSyncDate();
//if (strLastSyncDate != "")
//{
// valueLastSyncDate = Convert.ToInt64(Convert.ToDateTime(strLastSyncDate).ToString("yyyyMMddHHmmss"));
//}
FileID = GetReturnFileID();
List<CDREntityDownloadsFile> listRangeCDREntityDownloadsFile = new List<CDREntityDownloadsFile>();
CDREntityDownloadsFile objCDREntityDownloadsFile = new CDREntityDownloadsFile();
string libName = string.Empty;
try
{
if (struserdomainId != "" && FileID != "")
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteurl))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
spWeb.AllowUnsafeUpdates = true;
SPUser newUser = spWeb.EnsureUser(struserdomainId);
bool hasPermissions = spListItemCollection[i].DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
string FolderName = spListItemCollection[i].Name;
//string FolderName = spListItemCollection[i].Folder.ToString();
SPFile spCompFileItem = spListItemCollection[i].File;
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItemCollection[i].Folder.Item["Modified"]).ToString("yyyyMMddHHmmss"));
if (hasPermissions == true)
{
try
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
spQueryfol.Query = @"<Where><Eq><FieldRef Name='UniqueId'/><Value Type='Text'>" + FileID + @"</Value></Eq></Where>";
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
SPFile spFile = spListItem.File;
bool hasPermissionsfile = spListItem.DoesUserHavePermissions(newUser, SPBasePermissions.ViewListItems);
if (hasPermissionsfile == true)
{
string FolderName1 = spListItem.Name;
byte[] content = spFile.OpenBinary();
if (spFile.UniqueId.ToString().ToLower() == FileID.ToLower())
{
string Path = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("cdradmin", "cdr@dm!n@1234", "service");
byte[] obj = wc.DownloadData(Path);
String FileDataBaseTo64 = Convert.ToBase64String(obj);
////sends the request, converts response to s stream
//HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Path);
//webRequest.UseDefaultCredentials = true;
//webRequest.PreAuthenticate = true;
//webRequest.Credentials = CredentialCache.DefaultCredentials;
//HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
//Stream reqStr = webResponse.GetResponseStream();
////reads the response stream
//StreamReader sr = new StreamReader(reqStr, System.Text.Encoding.UTF8);
//string content1 = String.Empty;
//content1 = sr.ReadToEnd();
objCDREntityDownloadsFile.fileid = FileID;
objCDREntityDownloadsFile.FilePath = Path;
objCDREntityDownloadsFile.FileData = FileDataBaseTo64;
listRangeCDREntityDownloadsFile.Add(objCDREntityDownloadsFile);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityDownloadsFile);
// Convert the sting to object
listRangeCDREntityDownloadsFile = null;
listRangeCDREntityDownloadsFile = helper.ConvertJSonToObject<List<CDREntityDownloadsFile>>(jsonResult);
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRangeCDREntityDownloadsFile.Count != 0)
{
return listRangeCDREntityDownloadsFile;
}
else
{
return listRangeCDREntityDownloadsFile;
}
}
#endregion
#region Add && delete User in user list
public List<CDREntityAdd_DelUser> Add_delUser()
{
List<CDREntityAdd_DelUser> listRangeCDREntityAdd_DelUser = new List<CDREntityAdd_DelUser>();
CDREntityAdd_DelUser objCDREntityAdd_DelUser = new CDREntityAdd_DelUser();
var struserdomainId = GetReturnUserIDdomain();
var strMode = GetReturnOpartionMode();
string[] userdomainId = struserdomainId.ToString().Split('|');
if (userdomainId.Length > 0 && strMode != "")
{
Mode = strMode;
if (userdomainId[0].Length > 0 && userdomainId[1].Length > 0)
{
userID = userdomainId[0];
domainID = userdomainId[1];
if (Mode.ToLower() == "add")
{
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList oList = web.Lists["CDRConfiguration"];
if (oList != null)
{
//Add a new item in the List
SPListItem item = oList.Items.Add();
item["Title"] = userID;
item["UserId"] = userID;
item["DomainID"] = domainID;
item["IsActive"] = 1;
item.Update();
objCDREntityAdd_DelUser.Status = "Success";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
objCDREntityAdd_DelUser.Status = "Failed";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
}
else if (Mode.ToLower() == "del")
{
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// create the site object
using (SPSite site = new SPSite(siteID))
{
// create the web object
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='UserId'/><Value Type='Text'>" + userID + @"</Value></Eq></Where>";
// create the list object
SPList oList = web.Lists["CDRConfiguration"];
//create the item collection object
SPListItemCollection itemcollection = oList.GetItems(query);
foreach (SPListItem item in itemcollection)
{
SPListItem itemToUpdate = oList.GetItemById(item.ID);
itemToUpdate["IsActive"] = 0;
// updating the data
itemToUpdate.Update();
objCDREntityAdd_DelUser.Status = "Success";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
objCDREntityAdd_DelUser.Status = "Failed";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
}
else
{
objCDREntityAdd_DelUser.Status = "Failed";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
}
}
return listRangeCDREntityAdd_DelUser;
}
#endregion
#region Get All File user wise permission in Only Second Lavel Of folder( Root Folder and Child Folder)
public List<CDREntitySLF> GetDocumentSLF()
{
var struserdomainId = GetReturnUserIDdomain();
CompanyID = GetReturnCompanyID();
if (CompanyID != "")
{
// get Company Name
try
{
///Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteurl))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists["CDRDocument"];
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + CompanyID + @"</Value></Eq></Where>";
// query.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
//query.RowLimit = 1;
SPListItemCollection items = spList.GetItems(query);
if (items.Count > 0)
{
SPListItem _item = items[0];
CompanyName = _item["Title"].ToString();
}
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
//
}
List<CDREntitySLF> listRangeCDREntitySLF = new List<CDREntitySLF>();
CDREntitySLF objCDREntitySLF = new CDREntitySLF();
string libName = string.Empty;
try
{
if (struserdomainId != "" && CompanyName != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
if (CompanyName == FolderName)
{
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
//string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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())
{
string name = spListItem["AccessLevel"].ToString();
if (name == "Y")
{
objCDREntitySLF.Company = spFile.ParentFolder.ToString();
objCDREntitySLF.UniqueId = spFile.UniqueId.ToString();
objCDREntitySLF.FileName = spFile.Name.Trim();
objCDREntitySLF.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
objCDREntitySLF.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntitySLF.Version = spFile.MajorVersion.ToString();
objCDREntitySLF.Status = "Success";
listRangeCDREntitySLF.Add(objCDREntitySLF);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntitySLF);
// Convert the sting to object
listRangeCDREntitySLF = null;
listRangeCDREntitySLF = helper.ConvertJSonToObject<List<CDREntitySLF>>(jsonResult);
}
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
//
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRangeCDREntitySLF.Count != 0)
{
return listRangeCDREntitySLF;
}
else
{
return listRangeCDREntitySLF;
}
}
#endregion
#region Get All File user wise permission in parent and child folder Company Wise
public List<CDREntity> GetDocumentCompanyWise()
{
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 strModifiedDate = GetReturnModifiedDate();
if (UniqueID != "")
{
// get Company Name
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists["CDRDocument"];
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + UniqueID + @"</Value></Eq></Where>";
// query.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
//query.RowLimit = 1;
SPListItemCollection items = spList.GetItems(query);
if (items.Count > 0)
{
SPListItem _item = items[0];
CompanyName = _item["Name"].ToString();
}
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
//
}
List<CDREntity> listRange = new List<CDREntity>();
CDREntity objCDREntity = new CDREntity();
string libName = string.Empty;
try
{
if (userID != "" && domainID != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
if (FolderName.ToLower() == CompanyName.ToLower())
{
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString().ToLower();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString().ToLower();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
// string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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())
{
objCDREntity.Company = spFile.ParentFolder.ToString();
//objCDREntity.CompanyId = spListItemCollection[i].ID.ToString();
objCDREntity.UniqueId = spFile.UniqueId.ToString();
objCDREntity.FileName = spFile.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// objCDREntity.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntity.Version = spFile.MajorVersion.ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDREntity>>(jsonResult);
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
//folder Loop
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRange.Count != 0)
{
return listRange;
}
else
{
return listRange;
}
}
#endregion
#region Get All File user wise permission in based on Company Name
public List<CDREntity> GetCompamyDocument()
{
List<CDREntity> listRange = new List<CDREntity>();
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())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
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)
{
CDREntity objCDREntity = new CDREntity();
//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)
{
objCDREntity.Company = CompanyName;
objCDREntity.UniqueId = spListItem.UniqueId.ToString();
// objCDREntity.CompanyId = spListItem.ID.ToString();
// objCDREntity.FolderName = spListItem.Name.Trim();
// objCDREntity.TimeStamp = spListItem.Folder.Item["Created"].ToString();
objCDREntity.Version = spListItem.Folder.Item["Version"].ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
}
else
{
objCDREntity.Company = CompanyName;
objCDREntity.UniqueId = spListItem.File.UniqueId.ToString();
// objCDREntity.CompanyId = spListItem.ID.ToString();
objCDREntity.FileName = spListItem.File.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spListItem.File.Url.Trim();
// objCDREntity.TimeStamp = spListItem.File.Item["Created"].ToString();
objCDREntity.Version = spListItem.File.Item["Version"].ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
}
}
}
}
}
}
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<CDREntity>>(jsonResult);
return listRange;
}
else
{
return listRange;
}
}
#endregion
#region Return Header Param userId |domain|FileId|Mode|CompanyID
public string GetReturnUserIDdomain()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strParam = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["UserID"] != null)
{
userID = headers["UserID"];
}
if (headers["domainID"] != null)
{
domainID = headers["domainID"];
}
break;
}
strParam = domainID + "\\" + userID;
return strParam;
}
public string GetReturnFileID()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strParamFileID = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["FileID"] != null)
{
FileID = headers["FileID"];
}
break;
}
strParamFileID = FileID;
return strParamFileID;
}
public string GetReturnOpartionMode()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strParamMode = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["Mode"] != null)
{
Mode = headers["Mode"];
}
break;
}
strParamMode = Mode;
return strParamMode;
}
public string GetReturnCompanyID()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strCompanyID = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["CompID"] != null)
{
CompanyID = headers["CompID"];
}
break;
}
strCompanyID = CompanyID;
return strCompanyID;
}
public string GetReturnCompanyName()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strCompanyName = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["CompanyName"] != null)
{
CompanyName = headers["CompanyName"];
}
break;
}
strCompanyName = CompanyName;
return strCompanyName;
}
public string GetReturnLastSyncDate()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strLastSyncDate = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["LastSyncDate"] != null)
{
LastSyncDate = headers["LastSyncDate"];
}
break;
}
strLastSyncDate = LastSyncDate;
return strLastSyncDate;
}
public string GetReturnModifiedDate()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strModifiedDate = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["ModifiedDate"] != null)
{
ModifiedDate = headers["ModifiedDate"];
}
break;
}
strModifiedDate = ModifiedDate;
return strModifiedDate;
}
public string GetReturnCompanyIDFromCDRDocumentList()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strUniqueID = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["UniqueID"] != null)
{
UniqueID = headers["UniqueID"];
}
break;
}
strUniqueID = UniqueID;
return strUniqueID;
}
#endregion
protected SPFolder GetNestedFolder(SPFolder spFolder, string strNestedFolderName)
{
spFolder = spFolder.SubFolders[strNestedFolderName];
return spFolder;
}
#region Get All File user wise permission in parent and child folder
public List<CDRModifiedEntity> GetModifiedDocument()
{
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 strModifiedDate = GetReturnModifiedDate();
List<CDRModifiedEntity> listRange = new List<CDRModifiedEntity>();
CDRModifiedEntity objCDRModifiedEntity = new CDRModifiedEntity();
string libName = string.Empty;
try
{
if (userID != "" && domainID != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
// Guid siteID = "https://stageone.motherson.com/sites/cdr";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString().ToLower();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString().ToLower();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
// string SPquery1 = @"<Where><Ge><FieldRef Name='Modified'IncludeTimeValue='TRUE'/><Value Type='DateTime'>2016-03-08T03:39:00Z</Value></Ge></Where>";
// string SPquery = @"<Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime'>2016-03-07 3:39</Value></Geq></Where>";
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
// spQueryfol.Query = SPquery1;
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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())
{
Double DiferenceDate = TimeDifferenceInMinutes(Convert.ToDateTime(spFile.Item["Modified"]), Convert.ToDateTime(strModifiedDate));
//objCDRModifiedEntity.Company = spFile.ParentFolder.ToString();
//objCDRModifiedEntity.UniqueId = spFile.UniqueId.ToString();
//objCDREntity.CompanyId = spListItem.ID.ToString();
if (DiferenceDate > 0)
{
objCDRModifiedEntity.FileName = spFile.Name.Trim();
objCDRModifiedEntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
objCDRModifiedEntity.Modified = spFile.Item["Modified"].ToString();
// objCDREntity.Status = "Success";
// objCDRModifiedEntity.Version = spFile.Item["Version"].ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDRModifiedEntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDRModifiedEntity>>(jsonResult);
}
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRange.Count != 0)
{
return listRange;
}
else
{
return listRange;
}
}
#endregion
public static double TimeDifferenceInMinutes(DateTime dateone, DateTime datetwo)
{
var duration = dateone - datetwo;
return duration.TotalMinutes;
}
}
}
4- Used Entity Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDRParrentfolderWPermission.Model
{
public class CDREntity
{
//public String CompanyId { get; set; }
//public String FolderName { get; set; }
public String FileName { get; set; }
public String FilePath { get; set; }
public String Company { get; set; }
// public String TimeStamp { get; set; }
public String Version { get; set; }
public String UniqueId { get; set; }
public String Action { get; set; }
public String LastSyncDate { get; set; }
// public string Status { get; set; }
}
public class CDREntityFolderWithoutPerMission
{
public String UniqueId { get; set; }
public String Company { get; set; }
public string Status { get; set; }
}
public class CDREntityFolderWithPerMission
{
public String UniqueId { get; set; }
public String Company { get; set; }
public String LogoPath { get; set; }
public string LogoData { get; set; }
public String LastSyncDate { get; set; }
public String Action { get; set; }
// public string Status { get; set; }
}
public class CDREntitySLF
{
public String UniqueId { get; set; }
public String FileName { get; set; }
public String FilePath { get; set; }
public String Company { get; set; }
public String TimeStamp { get; set; }
public String Version { get; set; }
public string Status { get; set; }
//public string FolderLavel { get; set; }
}
public class CDREntityDownloadsFile
{
public String fileid { get; set; }
public String FilePath { get; set; }
public string FileData { get; set; }
}
public class CDREntityAdd_DelUser
{
public string Status { get; set; }
}
public class CDRModifiedEntity
{
//public String CompanyId { get; set; }
//public String FolderName { get; set; }
public String FileName { get; set; }
public String FilePath { get; set; }
// public String Company { get; set; }
public String Modified { get; set; }
// public String Version { get; set; }
// public String UniqueId { get; set; }
// public string Status { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDRParrentfolderWPermission.Model
{
public class CDRErrorLog
{
public void WriteLog(string strLog)
{
System.IO.StreamWriter log;
FileStream fileStream = null;
DirectoryInfo logDirInfo = null;
FileInfo logFileInfo;
//string Folderpath = WebConfigurationManager.AppSettings["ErrorFolderpath"].ToString();
string logFilePath = "C:\\Logs\\";
// string logFilePath = Folderpath;
logFilePath = logFilePath + "CDRParrentfolderWPermission" + "_" + System.DateTime.Today.ToString("dd-MM-yyyy") + "." + "txt";
logFileInfo = new FileInfo(logFilePath);
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
if (!logDirInfo.Exists) logDirInfo.Create();
if (!logFileInfo.Exists)
{
fileStream = logFileInfo.Create();
}
else
{
fileStream = new FileStream(logFilePath, FileMode.Append);
}
log = new StreamWriter(fileStream);
log.WriteLine("*******************************" + DateTime.Now + "********************************");
log.WriteLine(strLog);
log.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
namespace CDRParrentfolderWPermission.Model
{
public class JSonHelper
{
public string ConvertObjectToJSon<T>(T obj)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, obj);
string jsonString = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
return jsonString;
}
public T ConvertJSonToObject<T>(string jsonString)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T obj = (T)serializer.ReadObject(ms);
return obj;
}
}
}
Others Way of getting permission based File and folder
using Microsoft.SharePoint.Client.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Activation;
using GETCDRDATA.Model;
using Microsoft.SharePoint;
using SP = Microsoft.SharePoint.Client;
using System.Runtime.Remoting.Contexts;
using System.ServiceModel.Web;
using System.Net;
using Microsoft.SharePoint.Client;
using System.Runtime.Serialization.Json;
using System.Web.Services;
using System.IO;
using System.Web;
using iTextSharp.text.pdf;
using System.Text;
using Microsoft.Web.Hosting.Administration;
using System.Data;
using iTextSharp.text.pdf.parser;
using System.util.collections;
using iTextSharp.text;
using System.Net.Mail;
using System.Collections.Specialized;
namespace GETCDRDATA.ISAPI
{
// All My Services Url
//http://0179nitiv002tvs:8120/_vti_bin/GETCDRDATA.svc/Add_delUser //userID,domainID
//http://0179nitiv002tvs:8120/_vti_bin/GETCDRDATA.svc/GetCompanyWP //userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
//http://0179nitiv002tvs:8120/_vti_bin/GETCDRDATA.svc/GetDocument //:userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
//http://0179nitiv002tvs:8120/_vti_bin/GETCDRDATA.svc/DownloadFile //userID,domainID,fileid
//http://0179nitiv002tvs:8120/_vti_bin/GETCDRDATA.svc/GetDocumentSLF //userID,domainID, CompID
//http://0179nitiv002tvs:8120/_vti_bin/GETCDRDATA.svc/GetModifiedDocument //userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
//chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html
//http://0179nitiv002tvs:8120/_vti_bin/GETCDRDATA.svc/GetDocumentCompanyWise
//http://0179nitiv002tvs:8120/_vti_bin/GETCDRDATA.svc/GetCompanyWOP -- not requred
//http://0179nitiv002tvs:8120/_vti_bin/GETCDRDATA.svc/GetCompamyDocument //userID:xyz,domainID:CR, LastSyncDate:2016-03-17 09:56:15
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class GETCDRDATA : IGETCDRDATA
{
CDRErrorLog objErrorLog = new CDRErrorLog();
string guidID = null;
string strgroupuserFolderdomain = string.Empty;
string strgroupuserFiledomain = string.Empty;
string userID = string.Empty;
string domainID = string.Empty;
string FileID = string.Empty;
string CompanyName = string.Empty;
string ModifiedDate = string.Empty;
string ServerDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string CompanyID = string.Empty;
string UniqueID = string.Empty;
SPWeb spWeb;
SPSite site;
SPList spList;
string LastSyncDate = string.Empty;
string Mode = string.Empty;
long valueModified;
long valueLastSyncDate = 0;
List<CDREntity> listRange1 = new List<CDREntity>();
CDREntity objCDREntity1 = new CDREntity();
#region Add && delete User in user list
public List<CDREntityAdd_DelUser> Add_delUser()
{
List<CDREntityAdd_DelUser> listRangeCDREntityAdd_DelUser = new List<CDREntityAdd_DelUser>();
CDREntityAdd_DelUser objCDREntityAdd_DelUser = new CDREntityAdd_DelUser();
var struserdomainId = GetReturnUserIDdomain();
var strMode = GetReturnOpartionMode();
string[] userdomainId = struserdomainId.ToString().Split('|');
if (userdomainId.Length > 0 && strMode != "")
{
Mode = strMode;
if (userdomainId[0].Length > 0 && userdomainId[1].Length > 0)
{
userID = userdomainId[0];
domainID = userdomainId[1];
if (Mode.ToLower() == "add")
{
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList oList = web.Lists["CDRConfiguration"];
if (oList != null)
{
//Add a new item in the List
SPListItem item = oList.Items.Add();
item["Title"] = userID;
item["UserId"] = userID;
item["DomainID"] = domainID;
item["IsActive"] = 1;
item.Update();
objCDREntityAdd_DelUser.Status = "Success";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
objCDREntityAdd_DelUser.Status = "Failed";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
}
else if (Mode.ToLower() == "del")
{
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// create the site object
using (SPSite site = new SPSite(siteID))
{
// create the web object
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='UserId'/><Value Type='Text'>" + userID + @"</Value></Eq></Where>";
// create the list object
SPList oList = web.Lists["CDRConfiguration"];
//create the item collection object
SPListItemCollection itemcollection = oList.GetItems(query);
foreach (SPListItem item in itemcollection)
{
SPListItem itemToUpdate = oList.GetItemById(item.ID);
itemToUpdate["IsActive"] = 0;
// updating the data
itemToUpdate.Update();
objCDREntityAdd_DelUser.Status = "Success";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
objCDREntityAdd_DelUser.Status = "Failed";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
}
else
{
objCDREntityAdd_DelUser.Status = "Failed";
listRangeCDREntityAdd_DelUser.Add(objCDREntityAdd_DelUser);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityAdd_DelUser);
// Convert the sting to object
listRangeCDREntityAdd_DelUser = null;
listRangeCDREntityAdd_DelUser = helper.ConvertJSonToObject<List<CDREntityAdd_DelUser>>(jsonResult);
}
}
}
return listRangeCDREntityAdd_DelUser;
}
#endregion
#region Get all Folder of directory permission based (as Company )
public List<CDREntityFolderWithPerMission> GetCompanyWP()
{
var struserdomainId = GetReturnUserIDdomain();
string[] userdomainId = struserdomainId.ToString().Split('|');
if (userdomainId.Length > 0)
{
if (userdomainId[0].Length > 0 && userdomainId[1].Length > 0)
{
userID = userdomainId[0];
domainID = userdomainId[1];
}
}
string strLastSyncDate = GetReturnLastSyncDate();
if (strLastSyncDate != "")
{
valueLastSyncDate = Convert.ToInt64(Convert.ToDateTime(strLastSyncDate).ToString("yyyyMMddHHmmss"));
}
List<CDREntityFolderWithPerMission> listRangeCDREntityFolderWithPerMission = new List<CDREntityFolderWithPerMission>();
CDREntityFolderWithPerMission objCDREntityFolderWithPerMission = new CDREntityFolderWithPerMission();
string libName = string.Empty;
try
{
if (userID != "" && domainID != "")
{
//string strfolder = string.Empty
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
// string FolderName= spListItemCollection[i].Folder.ToString();
SPFile spCompFileItem = spListItemCollection[i].File;
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItemCollection[i].Folder.Item["Modified"]).ToString("yyyyMMddHHmmss"));
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
// Start Getting Company Logo
try
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
spList = spWeb.Lists.TryGetList("CDRCompanyLogo");
SPQuery spQueryCopfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spList.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryCopfol.Folder = folder;
spQueryCopfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection Compitems = spList.GetItems(spQueryCopfol);
foreach (SPListItem spListCompItem in Compitems)
{
SPFile spCompFile = spListCompItem.File;
if (spCompFile.ToString() != null)
{
byte[] content = spCompFile.OpenBinary();
string Path = spWeb.Url.Trim() + @"/" + spCompFile.Url.Trim();
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("cdradmin", "cdr@dm!n@1234", "service");
byte[] obj = wc.DownloadData(Path);
String FileDataBaseTo64 = Convert.ToBase64String(obj);
objCDREntityFolderWithPerMission.LogoPath = Path;
objCDREntityFolderWithPerMission.LogoData = FileDataBaseTo64;
}
break;
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
// End Company Logo
if (strLastSyncDate != "")
{
if (valueLastSyncDate < valueModified)
{
objCDREntityFolderWithPerMission.Company = spListItemCollection[i].Name;
// objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].UniqueId.ToString();
objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].ID.ToString();
// objCDREntityFolderWithPerMission.Status = "Success";
objCDREntityFolderWithPerMission.Action ="Update";
objCDREntityFolderWithPerMission.LastSyncDate = ServerDate;
listRangeCDREntityFolderWithPerMission.Add(objCDREntityFolderWithPerMission);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityFolderWithPerMission);
// Convert the sting to object
listRangeCDREntityFolderWithPerMission = null;
listRangeCDREntityFolderWithPerMission = helper.ConvertJSonToObject<List<CDREntityFolderWithPerMission>>(jsonResult);
}
}
else
{
objCDREntityFolderWithPerMission.Company = spListItemCollection[i].Name;
// objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].UniqueId.ToString();
objCDREntityFolderWithPerMission.UniqueId = spListItemCollection[i].ID.ToString();
// objCDREntityFolderWithPerMission.Status = "Success";
objCDREntityFolderWithPerMission.Action = "Insert";
objCDREntityFolderWithPerMission.LastSyncDate = ServerDate;
listRangeCDREntityFolderWithPerMission.Add(objCDREntityFolderWithPerMission);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityFolderWithPerMission);
// Convert the sting to object
listRangeCDREntityFolderWithPerMission = null;
listRangeCDREntityFolderWithPerMission = helper.ConvertJSonToObject<List<CDREntityFolderWithPerMission>>(jsonResult);
}
}
}
}
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
return listRangeCDREntityFolderWithPerMission;
}
if (listRangeCDREntityFolderWithPerMission.Count != 0)
{
return listRangeCDREntityFolderWithPerMission;
}
else
{
return listRangeCDREntityFolderWithPerMission;
}
}
#endregion
#region Get All File user wise permission in parent and child folder
public List<CDREntity> GetDocument()
{
List<CDREntity> listRange = new List<CDREntity>();
CDREntity objCDREntity = new CDREntity();
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 strLastSyncDate = GetReturnLastSyncDate();
if (strLastSyncDate != "")
{
valueLastSyncDate = Convert.ToInt64(Convert.ToDateTime(strLastSyncDate).ToString("yyyyMMddHHmmss"));
}
string libName = string.Empty;
try
{
if (userID != "" && domainID != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString().ToLower();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString().ToLower();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
string libraryName = "CDRDocument/"; //used for
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
spQueryfol.Query = @"<Where><Eq><FieldRef Name='Approval_Status'/><Value Type='Text'>Approved</Value></Eq></Where>";
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
// string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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 (strLastSyncDate != "")
{
if (Convert.ToDateTime(spListItem.File.Item["Visible Date"]).ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
{
valueModified = Convert.ToInt64(Convert.ToDateTime(spListItem.File.Item["Modified"]).ToString("yyyyMMddHHmmss"));
if (valueLastSyncDate < valueModified)
{
objCDREntity.Company = spFile.ParentFolder.ToString().Remove(0, libraryName.Length);
objCDREntity.UniqueId = spFile.UniqueId.ToString();
//objCDREntity.CompanyId = spListItem.ID.ToString();
objCDREntity.FileName = spFile.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// objCDREntity.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntity.Version = spFile.MajorVersion.ToString();
objCDREntity.LastSyncDate = ServerDate;
objCDREntity.Action = "Update";
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDREntity>>(jsonResult);
}
}
}
else
{
//if (Convert.ToDateTime(spListItem.File.Item["Visible Date"]).ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
//{
objCDREntity.Company = spFile.ParentFolder.ToString().Remove(0, libraryName.Length);
objCDREntity.UniqueId = spFile.UniqueId.ToString();
//objCDREntity.CompanyId = spListItem.ID.ToString();
objCDREntity.FileName = spFile.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// objCDREntity.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntity.Version = spFile.MajorVersion.ToString();
objCDREntity.LastSyncDate = ServerDate;
objCDREntity.Action = "Insert";
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDREntity>>(jsonResult);
// }
}
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
// }
if (listRange.Count != 0)
{
return listRange;
}
else
{
return listRange;
}
}
#endregion
#region Get Downlaods File Name In In ToBase64String On Basis of Token Id and Guid Id of document
public List<CDREntityDownloadsFile> DownloadFile()
{
var struserdomainId = GetReturnUserIDdomain();
string[] userdomainId = struserdomainId.ToString().Split('|');
if (userdomainId.Length > 0)
{
if (userdomainId[0].Length > 0 && userdomainId[1].Length > 0)
{
userID = userdomainId[0];
domainID = userdomainId[1];
}
}
FileID = GetReturnFileID();
List<CDREntityDownloadsFile> listRangeCDREntityDownloadsFile = new List<CDREntityDownloadsFile>();
CDREntityDownloadsFile objCDREntityDownloadsFile = new CDREntityDownloadsFile();
string libName = string.Empty;
try
{
if (userID != "" && domainID != "" && FileID != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb= site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
byte[] content = spFile.OpenBinary();
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 (spFile.UniqueId.ToString().ToLower() == FileID.ToLower())
{
string Path = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("cdradmin", "cdr@dm!n@1234", "service");
byte[] obj = wc.DownloadData(Path);
String FileDataBaseTo64 = Convert.ToBase64String(obj);
////sends the request, converts response to s stream
//HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Path);
//webRequest.UseDefaultCredentials = true;
//webRequest.PreAuthenticate = true;
//webRequest.Credentials = CredentialCache.DefaultCredentials;
//HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
//Stream reqStr = webResponse.GetResponseStream();
////reads the response stream
//StreamReader sr = new StreamReader(reqStr, System.Text.Encoding.UTF8);
//string content1 = String.Empty;
//content1 = sr.ReadToEnd();
objCDREntityDownloadsFile.fileid = FileID;
objCDREntityDownloadsFile.FilePath = Path;
objCDREntityDownloadsFile.FileData = FileDataBaseTo64;
listRangeCDREntityDownloadsFile.Add(objCDREntityDownloadsFile);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntityDownloadsFile);
// Convert the sting to object
listRangeCDREntityDownloadsFile = null;
listRangeCDREntityDownloadsFile = helper.ConvertJSonToObject<List<CDREntityDownloadsFile>>(jsonResult);
}
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRangeCDREntityDownloadsFile.Count != 0)
{
return listRangeCDREntityDownloadsFile;
}
else
{
return listRangeCDREntityDownloadsFile;
}
}
#endregion
#region Get All File user wise permission in Only Second Lavel Of folder( Root Folder and Child Folder)
public List<CDREntitySLF> GetDocumentSLF()
{
var struserdomainId = GetReturnUserIDdomain();
string[] userdomainId = struserdomainId.ToString().Split('|');
if (userdomainId.Length > 0)
{
if (userdomainId[0].Length > 0 && userdomainId[1].Length > 0)
{
userID = userdomainId[0];
domainID = userdomainId[1];
}
}
CompanyID = GetReturnCompanyID();
if (CompanyID != "")
{
// get Company Name
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists["CDRDocument"];
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + CompanyID + @"</Value></Eq></Where>";
// query.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
//query.RowLimit = 1;
SPListItemCollection items = spList.GetItems(query);
if (items.Count > 0)
{
SPListItem _item = items[0];
CompanyName = _item["Title"].ToString();
}
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
//
}
List<CDREntitySLF> listRangeCDREntitySLF = new List<CDREntitySLF>();
CDREntitySLF objCDREntitySLF = new CDREntitySLF();
string libName = string.Empty;
try
{
if (userID != "" && domainID != "" && CompanyName != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
if (CompanyName == FolderName)
{
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
//string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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())
{
string name = spListItem["AccessLevel"].ToString();
if (name == "Y")
{
objCDREntitySLF.Company = spFile.ParentFolder.ToString();
objCDREntitySLF.UniqueId = spFile.UniqueId.ToString();
objCDREntitySLF.FileName = spFile.Name.Trim();
objCDREntitySLF.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
objCDREntitySLF.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntitySLF.Version = spFile.MajorVersion.ToString();
objCDREntitySLF.Status = "Success";
listRangeCDREntitySLF.Add(objCDREntitySLF);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRangeCDREntitySLF);
// Convert the sting to object
listRangeCDREntitySLF = null;
listRangeCDREntitySLF = helper.ConvertJSonToObject<List<CDREntitySLF>>(jsonResult);
}
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
//
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRangeCDREntitySLF.Count != 0)
{
return listRangeCDREntitySLF;
}
else
{
return listRangeCDREntitySLF;
}
}
#endregion
#region Get All File user wise permission in parent and child folder Company Wise
public List<CDREntity> GetDocumentCompanyWise()
{
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 strModifiedDate = GetReturnModifiedDate();
if (UniqueID != "")
{
// get Company Name
try
{
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists["CDRDocument"];
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + UniqueID + @"</Value></Eq></Where>";
// query.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
//query.RowLimit = 1;
SPListItemCollection items = spList.GetItems(query);
if (items.Count > 0)
{
SPListItem _item = items[0];
CompanyName = _item["Name"].ToString();
}
}
}
});
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
//
}
List<CDREntity> listRange = new List<CDREntity>();
CDREntity objCDREntity = new CDREntity();
string libName = string.Empty;
try
{
if (userID != "" && domainID != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
if (FolderName.ToLower() == CompanyName.ToLower())
{
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString().ToLower();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString().ToLower();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
// string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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())
{
objCDREntity.Company = spFile.ParentFolder.ToString();
//objCDREntity.CompanyId = spListItemCollection[i].ID.ToString();
objCDREntity.UniqueId = spFile.UniqueId.ToString();
objCDREntity.FileName = spFile.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// objCDREntity.TimeStamp = spFile.TimeLastModified.ToString();
objCDREntity.Version = spFile.MajorVersion.ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDREntity>>(jsonResult);
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
//folder Loop
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRange.Count != 0)
{
return listRange;
}
else
{
return listRange;
}
}
#endregion
#region Get All File user wise permission in based on Company Name
public List<CDREntity> GetCompamyDocument()
{
List<CDREntity> listRange = new List<CDREntity>();
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())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
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)
{
CDREntity objCDREntity = new CDREntity();
//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)
{
objCDREntity.Company = CompanyName;
objCDREntity.UniqueId = spListItem.UniqueId.ToString();
// objCDREntity.CompanyId = spListItem.ID.ToString();
// objCDREntity.FolderName = spListItem.Name.Trim();
// objCDREntity.TimeStamp = spListItem.Folder.Item["Created"].ToString();
objCDREntity.Version = spListItem.Folder.Item["Version"].ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
}
else
{
objCDREntity.Company = CompanyName;
objCDREntity.UniqueId = spListItem.File.UniqueId.ToString();
// objCDREntity.CompanyId = spListItem.ID.ToString();
objCDREntity.FileName = spListItem.File.Name.Trim();
objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spListItem.File.Url.Trim();
// objCDREntity.TimeStamp = spListItem.File.Item["Created"].ToString();
objCDREntity.Version = spListItem.File.Item["Version"].ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDREntity);
}
}
}
}
}
}
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<CDREntity>>(jsonResult);
return listRange;
}
else
{
return listRange;
}
}
#endregion
#region Return Header Param userId |domain|FileId|Mode|CompanyID
public string GetReturnUserIDdomain()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strParam = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["UserID"] != null)
{
userID = headers["UserID"];
}
if (headers["domainID"] != null)
{
domainID = headers["domainID"];
}
break;
}
strParam = userID + "|" + domainID;
return strParam;
}
public string GetReturnFileID()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strParamFileID = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["FileID"] != null)
{
FileID = headers["FileID"];
}
break;
}
strParamFileID = FileID;
return strParamFileID;
}
public string GetReturnOpartionMode()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strParamMode = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["Mode"] != null)
{
Mode = headers["Mode"];
}
break;
}
strParamMode = Mode;
return strParamMode;
}
public string GetReturnCompanyID()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strCompanyID = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["CompID"] != null)
{
CompanyID = headers["CompID"];
}
break;
}
strCompanyID = CompanyID;
return strCompanyID;
}
public string GetReturnCompanyName()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strCompanyName = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["CompanyName"] != null)
{
CompanyName = headers["CompanyName"];
}
break;
}
strCompanyName = CompanyName;
return strCompanyName;
}
public string GetReturnLastSyncDate()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strLastSyncDate = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["LastSyncDate"] != null)
{
LastSyncDate = headers["LastSyncDate"];
}
break;
}
strLastSyncDate = LastSyncDate;
return strLastSyncDate;
}
public string GetReturnModifiedDate()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strModifiedDate = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["ModifiedDate"] != null)
{
ModifiedDate = headers["ModifiedDate"];
}
break;
}
strModifiedDate = ModifiedDate;
return strModifiedDate;
}
public string GetReturnCompanyIDFromCDRDocumentList()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
string strUniqueID = string.Empty;
for (int i = 0; i < headers.Count; i++)
{
if (headers["UniqueID"] != null)
{
UniqueID = headers["UniqueID"];
}
break;
}
strUniqueID = UniqueID;
return strUniqueID;
}
#endregion
protected SPFolder GetNestedFolder(SPFolder spFolder, string strNestedFolderName)
{
spFolder = spFolder.SubFolders[strNestedFolderName];
return spFolder;
}
#region Get All File user wise permission in parent and child folder
public List<CDRModifiedEntity> GetModifiedDocument()
{
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 strModifiedDate = GetReturnModifiedDate();
List<CDRModifiedEntity> listRange = new List<CDRModifiedEntity>();
CDRModifiedEntity objCDRModifiedEntity = new CDRModifiedEntity();
string libName = string.Empty;
try
{
if (userID != "" && domainID != "")
{
//string strfolder = string.Empty;
Guid siteID = SPContext.Current.Site.ID;
// Guid siteID = "https://stageone.motherson.com/sites/cdr";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(siteID))
{
using (spWeb = site.OpenWeb())
{
spList = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQuery = new SPQuery();
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
if (spListItemCollection.Count > 0)
{
for (int i = 0; i < spListItemCollection.Count; i++)
{
if (spListItemCollection[i].RoleAssignments.Count > 0)
{
string FolderName = spListItemCollection[i].Name;
SPRoleAssignmentCollection assignPermissionFol = spListItemCollection[i].RoleAssignments;
foreach (SPRoleAssignment assignmentPerFolMember in assignPermissionFol)
{
//string dogCsv = string.Join(",", assignment.Member.Name);
string userdomainFoldername = string.Join(",", assignmentPerFolMember.Member);
//string dogCsv3 = string.Join(",", assignment.Member.ID);
bool VolidloginName = userdomainFoldername.Contains("\\");
if (VolidloginName == true)
{
string[] groupuser = userdomainFoldername.ToString().Split('\\');
if (groupuser[1].ToString() != "" && groupuser[0].ToString() != "")
{
if (groupuser[0].Contains("|"))
{
string[] strgroupuserdomain = groupuser[0].ToString().Split('|');
strgroupuserFolderdomain = strgroupuserdomain[1].ToString().ToLower();
}
else
{
strgroupuserFolderdomain = groupuser[0].ToString().ToLower();
}
if (groupuser[1].ToString().ToLower() == userID.ToLower() && strgroupuserFolderdomain.ToLower() == domainID.ToLower())
{
try
{
using (site = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = site.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
SPQuery spQueryfol = new SPQuery();
// string SPquery1 = @"<Where><Ge><FieldRef Name='Modified'IncludeTimeValue='TRUE'/><Value Type='DateTime'>2016-03-08T03:39:00Z</Value></Ge></Where>";
// string SPquery = @"<Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime'>2016-03-07 3:39</Value></Geq></Where>";
//Getting the folder object from the list
SPFolder folder = spListfol.RootFolder.SubFolders[FolderName];
//Set the Folder property
spQueryfol.Folder = folder;
spQueryfol.ViewAttributes = "Scope=\"Recursive\"";
// spQueryfol.Query = SPquery1;
SPListItemCollection items = spList.GetItems(spQueryfol);
foreach (SPListItem spListItem in items)
{
string FolderName1 = spListItem.Name;
SPFile spFile = spListItem.File;
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())
{
Double DiferenceDate = TimeDifferenceInMinutes(Convert.ToDateTime(spFile.Item["Modified"]), Convert.ToDateTime(strModifiedDate));
//objCDRModifiedEntity.Company = spFile.ParentFolder.ToString();
//objCDRModifiedEntity.UniqueId = spFile.UniqueId.ToString();
//objCDREntity.CompanyId = spListItem.ID.ToString();
if (DiferenceDate> 0)
{
objCDRModifiedEntity.FileName = spFile.Name.Trim();
objCDRModifiedEntity.FilePath = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
objCDRModifiedEntity.Modified = spFile.Item["Modified"].ToString();
// objCDREntity.Status = "Success";
// objCDRModifiedEntity.Version = spFile.Item["Version"].ToString();
// objCDREntity.Status = "Success";
listRange.Add(objCDRModifiedEntity);
JSonHelper helper = new JSonHelper();
String jsonResult = helper.ConvertObjectToJSon(listRange);
// Convert the sting to object
listRange = null;
listRange = helper.ConvertJSonToObject<List<CDRModifiedEntity>>(jsonResult);
}
}
}
}
}
}
spWeb.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
}
}
}
}
}
}
}
}
});
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
if (listRange.Count != 0)
{
return listRange;
}
else
{
return listRange;
}
}
#endregion
public static double TimeDifferenceInMinutes(DateTime dateone, DateTime datetwo)
{
var duration = dateone - datetwo;
return duration.TotalMinutes;
}
//#region Get All File user wise permission in parent and child folder
//public List<CDREntity> GetDocument()
//{
// List<CDREntity> listRange = new List<CDREntity>();
// 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 = "CDRDocument/"; //used for
// spWeb.AllowUnsafeUpdates = true;
// SPList spListfol = spWeb.Lists.TryGetList("CDRDocument");
// 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)
// {
// CDREntity objCDREntity = new CDREntity();
// //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)
// {
// // objCDREntity.Company = CompanyName;
// objCDREntity.Company = spListItem.Folder.ParentFolder.ToString().Remove(0, libraryName.Length);
// objCDREntity.UniqueId = spListItem.UniqueId.ToString();
// // objCDREntity.CompanyId = spListItem.ID.ToString();
// objCDREntity.FolderName = spListItem.Name.Trim();
// objCDREntity.TimeStamp = spListItem.Folder.Item["Created"].ToString();
// objCDREntity.Version = spListItem.Folder.Item["Version"].ToString();
// // objCDREntity.Status = "Success";
// listRange.Add(objCDREntity);
// }
// else
// {
// objCDREntity.Company = spListItem.File.ParentFolder.ToString().Remove(0, libraryName.Length);
// objCDREntity.UniqueId = spListItem.File.UniqueId.ToString();
// // objCDREntity.CompanyId = spListItem.ID.ToString();
// objCDREntity.FileName = spListItem.File.Name.Trim();
// objCDREntity.FilePath = spWeb.Url.Trim() + @"/" + spListItem.File.Url.Trim();
// objCDREntity.TimeStamp = spListItem.File.Item["Created"].ToString();
// objCDREntity.Version = spListItem.File.Item["Version"].ToString();
// // objCDREntity.Status = "Success";
// listRange.Add(objCDREntity);
// }
// }
// }
// }
// }
// }
// 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<CDREntity>>(jsonResult);
// return listRange;
// }
// else
// {
// return listRange;
// }
//}
//#endregion
}
}
No comments:
Post a Comment