当前位置: 首页>>代码示例>>C#>>正文


C# ClientContext.Dispose方法代码示例

本文整理汇总了C#中ClientContext.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ClientContext.Dispose方法的具体用法?C# ClientContext.Dispose怎么用?C# ClientContext.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClientContext的用法示例。


在下文中一共展示了ClientContext.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAuthenticatedContext

        /// <summary>
        /// This method will return a ClientContext object with the authentication cookie set.
        /// The ClientContext should be disposed of as any other IDisposable
        /// </summary>
        /// <param name="targetSiteUrl"></param>
        /// <returns></returns>
        public static ClientContext GetAuthenticatedContext(string targetSiteUrl, int popUpWidth, int popUpHeight)
        {
            CookieCollection cookies = null;
            cookies = GetAuthenticatedCookies(targetSiteUrl, popUpWidth, popUpHeight);
            if (cookies == null) return null;

            ClientContext context = new ClientContext(targetSiteUrl);
            try
            {
                context.ExecutingWebRequest += delegate(object sender, WebRequestEventArgs e)
                {
                    e.WebRequestExecutor.WebRequest.CookieContainer = new CookieContainer();
                    foreach (Cookie cookie in cookies)
                    {
                        e.WebRequestExecutor.WebRequest.CookieContainer.Add(cookie);
                    }
                };
            }
            catch
            {
                if (context != null) context.Dispose();
                throw;
            }

            return context;
        }
开发者ID:emp,项目名称:SharePointOnlineDeploy,代码行数:32,代码来源:ClaimClientContext.cs

示例2: GetAuthenticatedContext

        /// <summary>
        /// This method will return a ClientContext object with the authentication cookie set.
        /// The ClientContext should be disposed of as any other IDisposable
        /// </summary>
        /// <param name="targetSiteUrl"></param>
        /// <returns></returns>
        public static ClientContext GetAuthenticatedContext(string targetSiteUrl, int popUpWidth, int popUpHeight)
        {
            CookieCollection cookies = null;
            cookies = ClaimClientContext.GetAuthenticatedCookies(targetSiteUrl, popUpWidth, popUpHeight);
            if (cookies == null) return null;

            ClientContext context = new ClientContext(targetSiteUrl);
            try
            {
                context.ExecutingWebRequest += delegate(object sender, WebRequestEventArgs e)
                {
                    //AJOUT POUR EVITER LES 403
                    e.WebRequestExecutor.WebRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"; 

                    e.WebRequestExecutor.WebRequest.CookieContainer = new CookieContainer();
                    foreach (Cookie cookie in cookies)
                    {
                        e.WebRequestExecutor.WebRequest.CookieContainer.Add(cookie);
                    }
                };
            }
            catch
            {
                if (context != null) context.Dispose();
                throw;
            }

            return context;
        }
开发者ID:qlestrelin,项目名称:icomierp,代码行数:35,代码来源:ClaimClientContext.cs

示例3: DownloadLatestFileList

        private void DownloadLatestFileList(object sender, ElapsedEventArgs e)
        {
            var clientContext = new ClientContext(_site) { Credentials = _credentials };
            try
            {
                var spList = clientContext.Web.Lists.GetByTitle(_list);
                clientContext.Load(spList);
                try
                {
                    clientContext.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    Log.WriteEntry(_site.AbsoluteUri + Environment.NewLine + ex.Message, EventLogEntryType.Error);
                    throw;
                }

                if (spList != null && spList.ItemCount > 0)
                {
                    var camlQuery = CreateQuery(_lastDownloadDateTime);

                    ListItemCollection listItems = spList.GetItems(camlQuery);
                    clientContext.Load(listItems);
                    try
                    {
                        if (Properties.Settings.Default.DebugMode)
                            Log.WriteEntry(
                                "Looking for changed files with query: " + Environment.NewLine +
                                camlQuery.ViewXml, EventLogEntryType.Information);

                        clientContext.ExecuteQuery();
                    }
                    catch (Exception ex)
                    {
                        Log.WriteEntry(_site.AbsoluteUri + Environment.NewLine + ex.Message, EventLogEntryType.Error);
                        throw;
                    }

                    if (Properties.Settings.Default.DebugMode)                    
                    {
                        var sb = new StringBuilder("Found " + listItems.Count + " changed files.");
                        sb.AppendLine();
                        foreach (var listItem in listItems)
                        {                            
                            var createdValue = listItem.FieldValues["Created"];
                            var urlValue = listItem["URL"] as FieldUrlValue;
                            var url = urlValue == null ? "" : urlValue.Url;
                            sb.AppendLine(createdValue + ": " + url);
                        }                        
                        Log.WriteEntry(sb.ToString(), EventLogEntryType.Information);
                    }
                    
                    // Push new items to queue
                    foreach (var listItem in listItems)
                    {
                        var createdValue = listItem.FieldValues["Created"];
                        if (!(createdValue is DateTime)) continue;
                        _lastDownloadDateTime = (DateTime)createdValue;

                        var urlValue = listItem["URL"] as FieldUrlValue;
                        if (urlValue == null) continue;

                        Uri uri;
                        if (!Uri.TryCreate(urlValue.Url, UriKind.Absolute, out uri)) continue;

                        // Make sure the download queue has not been stopped
                        if (!_queue.IsAddingCompleted)
                        {
                            // Make sure the file is not already added to the queue
                            if (_queue.All(x => x.AbsoluteUri != uri.AbsoluteUri)) _queue.Add(uri);
                        }
                        else
                        {
                            // If the download queue has been stopped, we break out of the for each...
                            break;
                        }
                    }
                }
            }
            finally
            {
                clientContext.Dispose();

                // Restart timer, it will trigger a download after the interval has passed
                if (_running)
                {
                    _timer.Start();
                }
            }
        }
开发者ID:egil,项目名称:SPADD,代码行数:90,代码来源:SPADDDownloadService.cs

示例4: SetUserValues

        private List<FieldUserValue> SetUserValues(IList<string> users)
        {
            var clientContext = new ClientContext(_sharePoint.Root);
            var rootWeb = clientContext.Web;

            var filteredUsers = new List<string>();

            foreach (var user in users)
            {
                try
                {
                    var ensureUser = rootWeb.EnsureUser(user);
                    clientContext.Load(ensureUser);
                    clientContext.ExecuteQuery();

                    filteredUsers.Add(user);
                }
                catch (Exception)
                {
                    // Do nothing, user does not exists. 
                }
            }

            clientContext.Dispose();

            if (filteredUsers.Count > 0)
            {
                return filteredUsers.Select(loginName => FieldUserValue.FromUser(loginName)).ToList();
            }

            return new List<FieldUserValue>();
        }
开发者ID:SharePointSusan,项目名称:Research-Data-Manager,代码行数:32,代码来源:SiteCreationRequestHelper.cs

示例5: GetMatters

        /// <summary>
        /// Gets the matters based on search criteria.
        /// </summary>
        /// <param name="searchRequestVM"></param>
        /// <returns></returns>
        public SearchResponseVM GetMatters(SearchRequestVM searchRequestVM)
        {
            SearchResponseVM searchResponseVM = null;
            var client = searchRequestVM.Client;
            var searchObject = searchRequestVM.SearchObject;
            try
            {
                clientContext = null;
                clientContext = spoAuthorization.GetClientContext(client.Url);
                KeywordQuery keywordQuery = new KeywordQuery(clientContext);
                if (string.IsNullOrWhiteSpace(searchObject.SearchTerm))
                {
                    searchObject.SearchTerm = ServiceConstants.ASTERISK;
                }

                if (searchObject.Filters != null)
                {
                    if (searchObject.Filters.FilterByMe == 1)
                    {

                        Users currentUserDetail = userDetails.GetLoggedInUserDetails(clientContext);
                        string userTitle = currentUserDetail.Name;
                        if(generalSettings.IsBackwardCompatible==false)
                        {
                            searchObject.SearchTerm = string.Concat(searchObject.SearchTerm, ServiceConstants.SPACE,
                            ServiceConstants.OPERATOR_AND, ServiceConstants.SPACE,
                            ServiceConstants.OPENING_BRACKET, searchSettings.ManagedPropertyResponsibleAttorney,
                            ServiceConstants.COLON, ServiceConstants.SPACE, ServiceConstants.DOUBLE_QUOTE, userTitle,
                            ServiceConstants.DOUBLE_QUOTE, ServiceConstants.SPACE, ServiceConstants.OPERATOR_AND, ServiceConstants.SPACE,
                            searchSettings.ManagedPropertyTeamMembers, ServiceConstants.COLON, ServiceConstants.SPACE,
                            ServiceConstants.DOUBLE_QUOTE, userTitle,
                            ServiceConstants.DOUBLE_QUOTE, ServiceConstants.SPACE, ServiceConstants.CLOSING_BRACKET);
                        }
                        else
                        {
                            searchObject.SearchTerm = string.Concat(searchObject.SearchTerm,
                                ServiceConstants.SPACE, ServiceConstants.OPERATOR_AND, ServiceConstants.SPACE,
                                ServiceConstants.OPENING_BRACKET, "CPCTeamMembers", ServiceConstants.COLON,
                                ServiceConstants.SPACE, ServiceConstants.DOUBLE_INVERTED_COMMA, userTitle,
                                ServiceConstants.DOUBLE_INVERTED_COMMA, ServiceConstants.SPACE, ServiceConstants.CLOSING_BRACKET);

                        }

                    }

                    keywordQuery = FilterMatters(searchObject, keywordQuery);

                    keywordQuery = KeywordQueryMetrics(client, searchObject, keywordQuery,
                        ServiceConstants.DOCUMENT_LIBRARY_FILTER_CONDITION,
                        searchSettings.ManagedPropertyIsMatter, true);

                    // Create a list of managed properties which are required to be present in search results
                    List<string> managedProperties = new List<string>();
                    managedProperties.Add(searchSettings.ManagedPropertyTitle);
                    managedProperties.Add(searchSettings.ManagedPropertyName);
                    managedProperties.Add(searchSettings.ManagedPropertyDescription);
                    managedProperties.Add(searchSettings.ManagedPropertySiteName);
                    managedProperties.Add(searchSettings.ManagedPropertyLastModifiedTime);
                    var managedColumns = configuration.GetSection("ContentTypes").GetSection("ManagedStampedColumns").GetChildren();
                    foreach (var key in managedColumns)
                    {                       
                            managedProperties.Add(searchSettings.ManagedPropertyExtension + key.Value.Replace("LPC", ""));
                    }
                    managedProperties.Add(searchSettings.ManagedPropertyMatterId);
                    managedProperties.Add(searchSettings.ManagedPropertyCustomTitle);
                    managedProperties.Add(searchSettings.ManagedPropertyPath);
                    managedProperties.Add(searchSettings.ManagedPropertyMatterName);
                    managedProperties.Add(searchSettings.ManagedPropertyOpenDate);
                    managedProperties.Add(searchSettings.ManagedPropertyClientName);
                    managedProperties.Add(searchSettings.ManagedPropertyBlockedUploadUsers);
                    managedProperties.Add(searchSettings.ManagedPropertyResponsibleAttorney);
                    managedProperties.Add(searchSettings.ManagedPropertyClientID);
                    managedProperties.Add(searchSettings.ManagedPropertyMatterGuid);
                    //Filter on Result source to fetch only Matter Center specific results
                    keywordQuery.SourceId = new Guid(searchSettings.SearchResultSourceID);
                    keywordQuery = AssignKeywordQueryValues(keywordQuery, managedProperties);
                    keywordQuery.BypassResultTypes = true;
                    searchResponseVM = FillResultData(clientContext, keywordQuery, searchRequestVM, true, managedProperties);
                }
                clientContext.Dispose();
                return searchResponseVM;
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }

        }
开发者ID:Microsoft,项目名称:mattercenter,代码行数:94,代码来源:Search.cs

示例6: Login

        /// <summary>
        /// Opens a Windows Forms Web Browser control to authenticate the user against an CLAIM site.
        /// </summary>
        /// <param name="popUpWidth"></param>
        /// <param name="popUpHeight"></param>
        public ClientContext Login()
        {
            // set login page url and success url from target site
            this.GetClaimParams(this._targetSiteUrl);
            if (string.IsNullOrEmpty(this.LoginPageUrl)) throw new ApplicationException(Constants.MSG_NOT_CLAIM_SITE);

            // navigate to the login page url.
            this._webBrowser.Navigate(this.LoginPageUrl);

            while (!stopLoginLoop)
            {
                Application.DoEvents();
                if (invokeMe is Action)
                {
                    lock (invokeMe)
                    {
                        ((Action)invokeMe)();
                        invokeMe = "";
                    }
                }
            }
            if (this.cancelLogin) return null;

            // see ClaimsWebBrowser_Navigated event

            if (this._cookies == null) return null;

            ClientContext context = new ClientContext(this._targetSiteUrl);
            try
            {
                context.ExecutingWebRequest += delegate(object sender, WebRequestEventArgs e)
                {
                    e.WebRequestExecutor.WebRequest.CookieContainer = new CookieContainer();
                    foreach (Cookie cookie in this._cookies)
                    {
                        e.WebRequestExecutor.WebRequest.CookieContainer.Add(cookie);
                    }
                };
            }
            catch
            {
                if (context != null) context.Dispose();
                throw;
            }

            return context;
        }
开发者ID:kerwal,项目名称:SharepointClientTest,代码行数:52,代码来源:ClientContextCreator.cs

示例7: GetDocuments

        /// <summary>
        /// Gets the matters based on search criteria.
        /// </summary>
        /// <param name="searchRequestVM"></param>
        /// <returns></returns>
        public SearchResponseVM GetDocuments(SearchRequestVM searchRequestVM)
        {
            SearchResponseVM searchResponseVM = null;
            try
            {
                var client = searchRequestVM.Client;
                var searchObject = searchRequestVM.SearchObject;
                clientContext = null;
                clientContext = spoAuthorization.GetClientContext(client.Url);
                KeywordQuery keywordQuery = new KeywordQuery(clientContext);
                if (string.IsNullOrWhiteSpace(searchObject.SearchTerm))
                {
                    searchObject.SearchTerm = ServiceConstants.ASTERISK;
                }

                if (searchObject.Filters != null)
                {
                    if (searchObject.Filters.FilterByMe == 1)
                    {
                        ////Get logged in user alias
                        Users currentUserDetail = userDetails.GetLoggedInUserDetails(clientContext);
                        string userTitle = currentUserDetail.Name;
                        searchObject.SearchTerm = String.Concat(searchObject.SearchTerm, ServiceConstants.SPACE, ServiceConstants.OPERATOR_AND, ServiceConstants.SPACE, searchSettings.ManagedPropertyAuthor, ServiceConstants.COLON, userTitle);
                    }

                    keywordQuery = FilterDocuments(searchObject, keywordQuery);

                    keywordQuery = KeywordQueryMetrics(client, searchObject, keywordQuery, ServiceConstants.DOCUMENT_ITEM_FILTER_CONDITION,
                        searchSettings.ManagedPropertyIsDocument, false);

                    // Create a list of managed properties which are required to be present in search results
                    List<string> managedProperties = new List<string>();
                    managedProperties.Add(searchSettings.ManagedPropertyFileName);
                    managedProperties.Add(searchSettings.ManagedPropertyTitle);
                    managedProperties.Add(searchSettings.ManagedPropertyCreated);
                    managedProperties.Add(searchSettings.ManagedPropertyUIVersionStringOWSTEXT);
                    managedProperties.Add(searchSettings.ManagedPropertyServerRelativeUrl);
                    managedProperties.Add(searchSettings.ManagedPropertyFileExtension);
                    managedProperties.Add(searchSettings.ManagedPropertyDocumentMatterId);
                    managedProperties.Add(searchSettings.ManagedPropertyDocumentLastModifiedTime);
                    managedProperties.Add(searchSettings.ManagedPropertySiteTitle);
                    managedProperties.Add(searchSettings.ManagedPropertyDocumentClientId);
                    managedProperties.Add(searchSettings.ManagedPropertyDocumentClientName);
                    managedProperties.Add(searchSettings.ManagedPropertyDocumentMatterName);
                    managedProperties.Add(searchSettings.ManagedPropertyDocumentId);
                    managedProperties.Add(searchSettings.ManagedPropertyCheckOutByUser);
                    managedProperties.Add(searchSettings.ManagedPropertySiteName);
                    managedProperties.Add(searchSettings.ManagedPropertySPWebUrl);
                    managedProperties.Add(searchSettings.ManagedPropertyDocumentVersion);
                    managedProperties.Add(searchSettings.ManagedPropertyDocumentCheckOutUser);
                    managedProperties.Add(searchSettings.ManagedPropertySPWebUrl);
                    managedProperties.Add(searchSettings.ManagedPropertyAuthor);
                    managedProperties.Add(searchSettings.ManagedPropertyMatterGuid);

                    //Filter on Result source to fetch only Matter Center specific results
                    keywordQuery.SourceId = new Guid(searchSettings.SearchResultSourceID);

                    var managedColumns = configuration.GetSection("ContentTypes").GetSection("ManagedStampedColumns").GetChildren();
                    foreach (var key in managedColumns)
                    {
                        managedProperties.Add(searchSettings.ManagedPropertyExtension + key.Value.Replace("LPC", ""));
                    }
                    //managedProperties.Add("PCPrePodDocumentPracticeGroup");
                    //managedProperties.Add("PCPrePodDocumentProjectType");
                    keywordQuery = AssignKeywordQueryValues(keywordQuery, managedProperties);
                    searchResponseVM = FillResultData(clientContext, keywordQuery, searchRequestVM, false, managedProperties);
                    clientContext.Dispose();
                }
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
            return searchResponseVM;
        }
开发者ID:Microsoft,项目名称:mattercenter,代码行数:81,代码来源:Search.cs

示例8: IsPublishingWeb

        private static bool IsPublishingWeb(ClientContext clientContext, Web web)
        {
            Logger.LogInfoMessage("Checking if the current web is a publishing web", false);

            var _IsPublished = false;
            var propName = "__PublishingFeatureActivated";

            try
            {

                //Ensure web properties are loaded
                if (!web.IsObjectPropertyInstantiated("AllProperties"))
                {
                    clientContext.Load(web, w => w.AllProperties);
                    clientContext.ExecuteQuery();
                }
                //Verify whether publishing feature is activated
                if (web.AllProperties.FieldValues.ContainsKey(propName))
                {
                    bool propVal;
                    Boolean.TryParse((string)web.AllProperties[propName], out propVal);
                    _IsPublished = propVal;
                    return propVal;
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage("[DeleteMissingWebparts: IsPublishingWeb]. Exception Message: "
                    + ex.Message + ", Exception Comments: Exception occured while finding publishing page", true);
                ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, web.Url, "Webpart", ex.Message,
                    ex.ToString(), "IsPublishingWeb", ex.GetType().ToString(), "Exception occured while finding publishing page");
            }
            finally
            {
                clientContext.Dispose();
                web = null;
            }
            return _IsPublished;
        }
开发者ID:OfficeDev,项目名称:PnP-Transformation,代码行数:39,代码来源:DeleteMissingWebparts.cs

示例9: testUrlForWeb

        /// <summary>
        /// Builds a client context and tries a simple query to test if there's a web.
        /// Returns 0 on success, negative if completely invalid, positive if SharePoint error (likely wrong creds).
        /// </summary>
        private static int testUrlForWeb(string url, System.Net.ICredentials userInfo, bool rethrow, out SP.ClientContext retCtx)
        {
            int result = -1;
            retCtx = null;
            SP.ClientContext ctx = new ClientContext(url);
            try
            {
                ctx.Credentials = userInfo;
                result = testContextForWeb(ctx, rethrow);
                if (result >= 0)
                {
                    retCtx = ctx;
                    ctx = null;
                }
            }
            finally { if (ctx != null) { ctx.Dispose(); } }

            return result;
        }
开发者ID:Xelio,项目名称:duplicati,代码行数:23,代码来源:SharePointBackend.cs

示例10: getFileID_SecondAlternate

        /// <summary>
        /// <c>getFileID_SecondAlternate</c> member function
        /// gets ID of the file uploaded to sharepoint document library when <c>getFileIDAlternate</c> member function  throw exception
        /// </summary>
        /// <param name="udataitem"></param>
        /// <param name="cmproperty"></param>
        /// <param name="siteurl"></param>
        /// <param name="docLibrary"></param>
        /// <returns></returns>
        private static string getFileID_SecondAlternate(SharePoint_Link.UserModule.UploadItemsData udataitem, CommonProperties cmproperty, string siteurl, string docLibrary)
        {
            string result = string.Empty;

            try
            {

                Microsoft.SharePoint.Client.ClientContext ct = new ClientContext(siteurl);
                ct.Credentials = ListWebClass.GetCredential(cmproperty);
                result = UpdateAttributes(udataitem, result, ct, cmproperty, docLibrary);

                ct.Dispose();
            }
            catch (Exception)
            {

                result = getFileIDByIteration(udataitem, cmproperty, siteurl, docLibrary);

            }
            return result;
        }
开发者ID:imysecy,项目名称:SPLINK,代码行数:30,代码来源:ListWebClass.cs

示例11: GetPageList

        private static List GetPageList(ClientContext clientContext)
        {
            List list = null;
            Web web = null;
            try
            {
                web = clientContext.Web;

                // Get a few properties from the web
                clientContext.Load(web,
                                    w => w.Url,
                                    w => w.ServerRelativeUrl,
                                    w => w.AllProperties,
                                    w => w.WebTemplate);

                clientContext.ExecuteQueryRetry();

                string pagesListID = string.Empty;
                bool _IsPublishingWeb = IsPublishingWeb(clientContext, web);

                if (_IsPublishingWeb)
                {
                    Logger.LogInfoMessage("Web: " + web.Url + "is a publishing web", false);
                    pagesListID = web.AllProperties["__PagesListId"] as string;
                    list = web.Lists.GetById(new Guid(pagesListID));

                    clientContext.Load(list, l => l.ForceCheckout,
                                       l => l.EnableVersioning,
                                       l => l.EnableMinorVersions,
                                       l => l.EnableModeration,
                                       l => l.Title,
                                       l => l.DraftVersionVisibility,
                                       l => l.DefaultViewUrl);

                    clientContext.ExecuteQueryRetry();

                }
                else
                {
                    Logger.LogInfoMessage("Web: " + web.Url + "is not a publishing web", false);
                    clientContext.Load(web.Lists);

                    clientContext.ExecuteQueryRetry();

                    try
                    {
                        //list = web.Lists.GetByTitle(Constants.TEAMSITE_PAGES_LIBRARY);
                        //WebPageLibrary, Wiki Page Library. Value = 119.
                        IEnumerable<List> libraries = clientContext.LoadQuery(web.Lists.Where(l => l.BaseTemplate == 119));
                        clientContext.ExecuteQuery();

                        if (libraries.Any() && libraries.Count() > 0)
                        {
                            list = libraries.First();
                        }

                        clientContext.Load(list);
                        clientContext.ExecuteQueryRetry();
                    }
                    catch
                    {
                        list = null;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage("[DeleteMissingWebparts: GetPageList]. Exception Message: " + ex.Message
                    + ", Exception Comments: Exception occured while finding page list", true);
                ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "Webpart", ex.Message,
                    ex.ToString(), "GetPageList", ex.GetType().ToString(), "Exception occured while finding page list");
            }
            finally
            {
                clientContext.Dispose();
                web = null;
            }
            return list;
        }
开发者ID:OfficeDev,项目名称:PnP-Transformation,代码行数:79,代码来源:DeleteMissingWebparts.cs

示例12: getFileIDByIteration

        /// <summary>
        /// <c>getFileIDByIteration</c> member function
        /// gets ID of the file uploaded to sharepoint document library when <c>getFileID_SecondAlternate</c> member function  throw exception
        /// </summary>
        /// <param name="udataitem"></param>
        /// <param name="cmproperty"></param>
        /// <param name="siteurl"></param>
        /// <param name="docLibrary"></param>
        /// <returns></returns>
        private static string getFileIDByIteration(SharePoint_Link.UserModule.UploadItemsData udataitem, CommonProperties cmproperty, string siteurl, string docLibrary)
        {
            string result = string.Empty;
            Microsoft.SharePoint.Client.ClientContext ct = new ClientContext(siteurl);
            try
            {

                ct.Credentials = ListWebClass.GetCredential(cmproperty);
                Web oWeb = ct.Web;
                ct.Load(oWeb);
                ct.ExecuteQuery();
                ListCollection currentListCollection = oWeb.Lists;
                ct.Load(currentListCollection);
                ct.ExecuteQuery();
                int found = 0;

                foreach (List oList in currentListCollection)
                {

                    string one = docLibrary.Trim();
                    string two = oList.Title.Trim();
                    int indexofspace = -1;
                    indexofspace = one.IndexOf(' ');
                    while (indexofspace != -1)
                    {
                        one = one.Remove(indexofspace, 1);
                        indexofspace = one.IndexOf(' ');
                    }
                    indexofspace = two.IndexOf(' ');
                    while (indexofspace != -1)
                    {
                        two = two.Remove(indexofspace, 1);
                        indexofspace = two.IndexOf(' ');
                    }

                    if (one == two)
                    {
                        List list2 = ct.Web.Lists.GetByTitle(oList.Title);
                        result = UpdateAttributes(udataitem, result, ct, cmproperty, docLibrary);
                        //old removed
                        found += 1;
                    }

                    if (found > 0)
                    {
                        break;
                    }

                }
            }
            catch (Exception)
            {

                try
                {
                    result = UpdateAttributes(udataitem, result, ct, cmproperty, docLibrary);
                }
                catch
                { }
            }
            ct.Dispose();
            return result;
        }
开发者ID:imysecy,项目名称:SPLINK,代码行数:72,代码来源:ListWebClass.cs

示例13: GetFileID

        /// <summary>
        /// <c>GetFileID</c> member function
        /// this member function is used to get ID of the file recently uploaded to sharepoint document library
        /// </summary>
        /// <param name="udataitem"></param>
        /// <param name="cmproperty"></param>
        /// <param name="leftpart"></param>
        /// <returns></returns>
        private static string GetFileID(SharePoint_Link.UserModule.UploadItemsData udataitem, CommonProperties cmproperty, string leftpart)
        {
            string test = cmproperty.SharepointLibraryURL;
            string result = string.Empty;
            try
            {
                Microsoft.SharePoint.Client.ClientContext ct = new ClientContext(cmproperty.LibSite);
                ct.Credentials = ListWebClass.GetCredential(cmproperty);

                result = UpdateAttributes(udataitem, result, ct, cmproperty, cmproperty.UploadDocLibraryName);
                ct.Dispose();
            }
            catch (Exception ex)
            {
                try
                {

                    result = getFileIDByIteration(udataitem, cmproperty, cmproperty.LibSite, cmproperty.UploadDocLibraryName);

                    if (string.IsNullOrEmpty(result))
                    {
                        ////////////////
                        if (leftpart.StartsWith("/"))
                        {
                            leftpart = leftpart.Remove(0, 1);
                        }
                        string temurl = cmproperty.LibSite + leftpart;
                        result = getFileIDAlternate(udataitem, cmproperty, temurl);

                        ///////////////////
                        if (string.IsNullOrEmpty(result))
                        {
                            result = getFileID_SecondAlternate(udataitem, cmproperty, cmproperty.LibSite, leftpart + cmproperty.UploadDocLibraryName);
                        }
                        /////////////////

                        if (string.IsNullOrEmpty(result))
                        {
                            string p = leftpart;

                            string[] split = p.Split('/');
                            int len = split.Length;

                            for (int i = len - 1; i > 0; i--)
                            {

                                int ind = p.LastIndexOf(split[i].ToString());
                                if (ind != -1)
                                {

                                    p = p.Remove(ind);
                                    temurl = cmproperty.LibSite + p;

                                    result = getFileIDAlternate(udataitem, cmproperty, temurl);

                                    if (!string.IsNullOrEmpty(result))
                                    {
                                        break;
                                    }
                                }
                            }

                            if (string.IsNullOrEmpty(result))
                            {
                                for (int i = 1; i < len - 1; i++)
                                {

                                    int ind = p.LastIndexOf(split[i].ToString());
                                    if (ind != -1)
                                    {

                                        p = p.Remove(ind);
                                        temurl = cmproperty.LibSite + p;

                                        result = getFileID_SecondAlternate(udataitem, cmproperty, cmproperty.LibSite, p + cmproperty.UploadDocLibraryName); getFileIDAlternate(udataitem, cmproperty, temurl);

                                        if (!string.IsNullOrEmpty(result))
                                        {
                                            break;
                                        }
                                    }

                                }
                            }

                        }
                    }
                    //////////////////
                }
                catch (Exception)
                {

//.........这里部分代码省略.........
开发者ID:imysecy,项目名称:SPLINK,代码行数:101,代码来源:ListWebClass.cs

示例14: GetSPListNameUsingClientOM

        /// <summary>
        /// <c>GetSPListNameUsingClientOM</c> member function
        /// gets the Sharepoint document library name for sharepoint 2010
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        public static Boolean GetSPListNameUsingClientOM(CommonProperties property)
        {
            Boolean result = false;
            try
            {

                //Get the list details by its name

                ClientContext clientcontext = new ClientContext(property.LibSite);

                List mylist = clientcontext.Web.Lists.GetByTitle(property.UploadDocLibraryName);
                try
                {
                    clientcontext.Credentials = property.Credentionals;
                    clientcontext.Load(clientcontext.Web);
                    clientcontext.Load(mylist);
                    clientcontext.ExecuteQuery();
                    result = true;
                    clientcontext.Dispose();
                }
                catch (Exception)
                {

                    try
                    {
                        clientcontext.Credentials = new System.Net.NetworkCredential(property.UserName, property.Password); // property.Credentionals;
                        clientcontext.Load(clientcontext.Web);
                        clientcontext.Load(mylist);
                        clientcontext.ExecuteQuery();
                        result = true;
                        clientcontext.Dispose();
                    }
                    catch (Exception)
                    {
                        string strdomainanduser = property.UserName;
                        int indx = strdomainanduser.LastIndexOf("\\");
                        if (indx != -1)
                        {
                            string domain = strdomainanduser.Substring(0, indx);
                            string uname = strdomainanduser.Substring(indx + 1);

                            clientcontext.Credentials = new System.Net.NetworkCredential(uname, property.Password, domain);
                            clientcontext.Load(clientcontext.Web);
                            clientcontext.Load(mylist);
                            clientcontext.ExecuteQuery();
                            result = true;
                            clientcontext.Dispose();

                        }

                    }
                }

            }
            catch (Exception ex)
            {

                result = false;
            }

            return result;
        }
开发者ID:imysecy,项目名称:SPLINK,代码行数:68,代码来源:ListWebClass.cs

示例15: GetCredential

        /// <summary>
        /// <c>GetCredential</c> member function
        /// gets the user credentials based on configuration settings and returns  ICredentials
        /// </summary>
        /// <param name="cProp"></param>
        /// <returns></returns>
        public static System.Net.ICredentials GetCredential(CommonProperties cProp)
        {
            System.Net.ICredentials result = null;
            try
            {

                //Get the list details by its name

                ClientContext clientcontext = new ClientContext(cProp.LibSite);

                List mylist = clientcontext.Web.Lists.GetByTitle(cProp.UploadDocLibraryName);
                try
                {
                    result = cProp.Credentionals;
                    clientcontext.Credentials = result;
                    clientcontext.Load(clientcontext.Web);
                    clientcontext.Load(mylist);
                    clientcontext.ExecuteQuery();
                    result = cProp.Credentionals;
                    clientcontext.Dispose();
                }
                catch (Exception)
                {

                    try
                    {
                        clientcontext.Credentials = new System.Net.NetworkCredential(cProp.UserName, cProp.Password); // property.Credentionals;
                        clientcontext.Load(clientcontext.Web);
                        clientcontext.Load(mylist);
                        clientcontext.ExecuteQuery();
                        result = new System.Net.NetworkCredential(cProp.UserName, cProp.Password);
                        clientcontext.Dispose();
                    }
                    catch (Exception)
                    {
                        string strdomainanduser = cProp.UserName;
                        int indx = strdomainanduser.LastIndexOf("\\");
                        if (indx != -1)
                        {
                            string domain = strdomainanduser.Substring(0, indx);
                            string uname = strdomainanduser.Substring(indx + 1);
                            try
                            {
                                clientcontext.Credentials = new System.Net.NetworkCredential(uname, cProp.Password, domain);
                                clientcontext.Load(clientcontext.Web);
                                clientcontext.Load(mylist);
                                clientcontext.ExecuteQuery();
                                result = new System.Net.NetworkCredential(uname, cProp.Password, domain);
                                clientcontext.Dispose();
                            }
                            catch (Exception)
                            {

                                result = cProp.Credentionals;
                            }

                        }

                    }
                }

            }
            catch (Exception ex)
            {

            }
            return result;
        }
开发者ID:imysecy,项目名称:SPLINK,代码行数:74,代码来源:ListWebClass.cs


注:本文中的ClientContext.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。