Пример #1
0
        /// <summary>
        /// returns the document stream using corresponding relative document path
        /// </summary>
        public static Stream GetStream(string id, string ext)
        {
            LLMainErr Model      = new LLMainErr();
            Stream    fileStream = null;
            string    fileName   = "";

            try
            {
                using (ClientContext ctx = GetContext())
                {
                    List olist             = ctx.Web.Lists.GetByTitle(ListName);
                    bool relativePathExist = urlDictProp.TryGetValue(Uri.EscapeDataString(id) + "." + ext, out string relativePath); //urlDictProp[id.ToString()];
                    if (relativePathExist)
                    {
                        Microsoft.SharePoint.Client.File file = ctx.Web.GetFileByServerRelativeUrl(relativePath);
                        ctx.Load(file);
                        ClientResult <Stream> streamX = file.OpenBinaryStream();
                        ctx.Load(file);
                        ctx.ExecuteQuery();
                        fileStream = streamX.Value;
                        fileStream.Seek(0, SeekOrigin.Begin);
                        fileName = file.Name;
                    }
                    else
                    {
                        fileStream = null;
                    }
                }
            }
            catch (Exception ex)
            {
                Model.Error = ex.Message;
            }
            return(fileStream);
        }
Пример #2
0
        /// <summary>
        /// Get SharePoint site context
        /// </summary>
        public static ClientContext GetContext()
        {
            LLMainErr     Model = new LLMainErr();
            ClientContext ctx   = null;

            try
            {
                string url      = WebConfigurationManager.AppSettings.Get("SPUrl");
                string appId    = WebConfigurationManager.AppSettings.Get("AppId");
                string secretId = WebConfigurationManager.AppSettings.Get("AppSecret");
                //string userName = WebConfigurationManager.AppSettings.Get("SPUserName");
                //string pass = WebConfigurationManager.AppSettings.Get("SPPassword");
                //SecureString password = new SecureString();
                //foreach (char c in pass)
                //{
                //    password.AppendChar(c);
                //}
                AuthenticationManager authManager = new AuthenticationManager();
                ctx = authManager.GetAppOnlyAuthenticatedContext(url, appId, secretId);
                ctx.Load(ctx.Web);
                ctx.ExecuteQuery();
                Console.WriteLine(ctx.Web.Title);
                //ctx = new ClientContext(url);
                //ctx.Credentials = new SharePointOnlineCredentials(userName, password);
            }
            catch (Exception ex)
            {
                Model.Error = ex.Message;
            }
            return(ctx);
        }
Пример #3
0
        /// <summary>
        /// Get SharePoint site context
        /// </summary>
        public static ClientContext GetContext()
        {
            LLMainErr     Model = new LLMainErr();
            ClientContext ctx   = null;

            try
            {
                string url      = WebConfigurationManager.AppSettings.Get("SPUrl");
                string appId    = WebConfigurationManager.AppSettings.Get("AppId");
                string secretId = WebConfigurationManager.AppSettings.Get("SecretId");

                AuthenticationManager authManager = new AuthenticationManager();
                ctx = authManager.GetAppOnlyAuthenticatedContext(url, appId, secretId);
                ctx.Load(ctx.Web);
                ctx.ExecuteQuery();
                Console.WriteLine(ctx.Web.Title);
            }
            catch (Exception ex)
            {
                Model.Error = ex.Message;
            }
            return(ctx);
        }
Пример #4
0
        /// <summary>
        /// Return All Page's Content
        /// </summary>
        public static List <LLMain> LoadLowesLinkContent()
        {
            lastKey = null;
            LLMainErr     Model          = new LLMainErr();
            List <LLMain> contentListObj = new List <LLMain>();

            /// <summary>
            /// contentListObj List of type LLMain storing all the Wiki page's content and other metadata properties
            /// </summary>
            try
            {
                using (ctx = GetContext())
                {
                    List      olist = ctx.Web.Lists.GetByTitle(ListName);
                    CamlQuery qry   = new CamlQuery();
                    qry.ViewXml = @"<View Scope='Recursive'>
                                     <Query>
                                     </Query>
                                </View>";

                    ListItemCollection listCol = olist.GetItems(qry);
                    ListItemCollection items   = listCol;
                    ctx.Load(items, icol => icol.Include(i => i["WikiField"], i => i.File.Name));
                    ctx.ExecuteQuery();
                    urlDictProp.Clear();
                    /// <summary>
                    /// Loop through all Wiki pages
                    /// </summary>
                    foreach (ListItem item in items)
                    {
                        /// <summary>
                        /// object intialization of type LLMain, for storing each wiki page's content and other metadata properties
                        /// </summary>
                        LLMain llmainPropObj = new LLMain();
                        llmainPropObj.PageName = Convert.ToString(item.File.Name);
                        llmainPropObj.Content  = Convert.ToString(item["WikiField"]);
                        /// <summary>
                        /// getting all the links from each wiki page's html content
                        /// </summary>
                        HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                        htmlDocument.LoadHtml(llmainPropObj.Content);
                        if (htmlDocument.DocumentNode.SelectNodes("//a") != null)
                        {
                            /// <summary>
                            /// Forming links for documents, internal page links and external page links
                            /// </summary>
                            llmainPropObj.Content = generateDocumentUrls(htmlDocument, llmainPropObj.Content);
                        }
                        /// <summary>
                        /// adding updated page's links and other content to List contentListObj of type LLMain
                        /// </summary>
                        contentListObj.Add(llmainPropObj);
                    }
                }
            }
            catch (Exception ex)
            {
                Model.Error = ex.Message;
            }
            return(contentListObj);
        }