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


C# SPSite类代码示例

本文整理汇总了C#中SPSite的典型用法代码示例。如果您正苦于以下问题:C# SPSite类的具体用法?C# SPSite怎么用?C# SPSite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: SaveAsso1

        void SaveAsso1()
        {
            ISharePointService sps = ServiceFactory.GetSharePointService(true);

            SPList list = sps.GetList(CAWorkFlowConstants.WorkFlowListName.StoreMaintenanceItems1.ToString());

            foreach (DataRow row in this.DataForm1.Asso1.Rows)
            {
                SPListItem item = list.Items.Add();
                item["WorkflowNumber"] = DataForm1.WorkflowNumber;
                item["Seq"] = row["Seq"];
                item["Reason"] = row["Reason"];
                item["Description"] = row["Description"];
                item["Remark"] = row["Remark"];
                try
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb web = site.OpenWeb(SPContext.Current.Site.RootWeb.ID))
                        {
                            item.Web.AllowUnsafeUpdates = true;
                            item.Update();
                            item.Web.AllowUnsafeUpdates = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("An error occured while updating the items");
                }

                //item.Web.AllowUnsafeUpdates = true;
                //item.Update();
            }
        }
开发者ID:porter1130,项目名称:C-A,代码行数:35,代码来源:NewForm.aspx.cs

示例2: GetSPChoiceFieldValue

        public System.Collections.Specialized.StringCollection GetSPChoiceFieldValue(string listName, string fieldName)
        {
            SPContext context = SPContext.Current;
            StringCollection fieldChoices = null;

            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite site = new SPSite(context.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb(context.Web.ID))
                    {
                        SPList list = web.Lists[listName];
                        SPField field = list.Fields[fieldName] as SPField;

                        if (field != null
                            && field.Type == SPFieldType.Choice)
                        {

                            fieldChoices = (field as SPFieldChoice).Choices;
                        }
                    }
                }
            });

            return fieldChoices;
        }
开发者ID:porter1130,项目名称:Medalsoft,代码行数:26,代码来源:SharepointEntry.cs

示例3: Execute

        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, StringDictionary keyValues, out string output)
        {
            output = string.Empty;

            string url = Params["url"].Value.TrimEnd('/');

            using (SPSite site = new SPSite(url))
            {
                using (SPWeb web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(url)])
                {

                    foreach (SPLanguage lang in web.RegionalSettings.InstalledLanguages)
                    {
                        foreach (SPWebTemplate template in site.GetWebTemplates((uint)lang.LCID))
                        {
                            output += template.Name + " = " + template.Title + " (" + lang.LCID + ")\r\n";
                        }
                        foreach (SPWebTemplate template in site.GetCustomWebTemplates((uint)lang.LCID))
                        {
                            output += template.Name + " = " + template.Title + " (Custom)(" + lang.LCID + ")\r\n";
                        }
                    }
                }
            }

            return (int)ErrorCodes.NoError;
        }
开发者ID:GSoft-SharePoint,项目名称:PowerShell-SPCmdlets,代码行数:34,代码来源:EnumInstalledSiteTemplates.cs

示例4: Main

        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://sam2012:33333"))
            {
                using (SPWeb web = site.OpenWeb("/sub"))
                {
                    web.AnonymousPermMask64 |= SPBasePermissions.UseRemoteAPIs;//SPBasePermissions.OpenItems;
                    Console.Write(web.AnonymousPermMask64);
                    Console.Write(web.DoesUserHavePermissions(SPBasePermissions.AddListItems));
                    SPList list = web.Lists["Temp"];
                    bool addItemPerm = list.DoesUserHavePermissions(SPBasePermissions.AddListItems);
                    Console.WriteLine(addItemPerm);
                    Console.WriteLine(list.AnonymousPermMask64);
                    web.Update();
                    Console.ReadKey();
                }
            }

            //byte[] sidBytes = UserPropertiesHelper.ConvertStringSidToSid("S-1-5-21-1343462910-744444023-3288617952-1638");
            //string loginName = PeopleEditor.GetAccountFromSid(sidBytes);
            //Console.WriteLine(loginName);
            //Console.ReadKey();

            //foreach (SPServer server in SPFarm.Local.Servers)
            //{
            //    Console.WriteLine(server.Name + "--" + server.Role);
            //    //Helper.Administration.Server.IsWebFrontEnd(server);
            //}
            //Console.ReadKey();
        }
开发者ID:shrenky,项目名称:SPTestLab,代码行数:30,代码来源:Program.cs

示例5: BindIdentificationType

 public static void BindIdentificationType(RadioButtonList rbList, string texto, string valor)
 {
     try
     {
     if (SPContext.Current != null)
     {
       using(Microsoft.SharePoint.SPWeb web = SPContext.Current.Web)
       {
         BLL.IdentificationTypeBLL bll = new CAFAM.WebPortal.BLL.IdentificationTypeBLL(web);
         DataSet ds = bll.GetIdentificationTypeList();
         BindList(rbList, ds, texto, valor);
       }
     }
     else
     {
       using(SPSite site = new SPSite(SP_SITE)){
         using(Microsoft.SharePoint.SPWeb web = site.OpenWeb())
         {
             BLL.IdentificationTypeBLL bll = new CAFAM.WebPortal.BLL.IdentificationTypeBLL(web);
             DataSet ds = bll.GetIdentificationTypeList();
             BindList(rbList, ds, texto, valor);
         }
       }
     }
     }
     catch (Exception ex)
     {
     throw ex;
     }
 }
开发者ID:gcode-mirror,项目名称:chafam,代码行数:30,代码来源:ListBinder.cs

示例6: ExportListToObjects

        public SharepointList ExportListToObjects(string siteUrl, string listName)
        {
            var list = new SPSite(siteUrl).OpenWeb().Lists[listName];
            var cols = new List<SharepointList.Column>();

            foreach (SPField field in list.Fields)
            {
                if(field.ReadOnlyField) continue;
                cols.Add(new SharepointList.Column()
                         {
                             Name = field.InternalName,
                             Type = field.FieldValueType
                         });
            }

            var rows = new List<SharepointList.Row>();
            foreach (SPListItem item in list.Items)
            {
                var values = new List<object>();
                foreach (SPField field in list.Fields)
                {
                    if (field.ReadOnlyField) continue;
                    values.Add(item[field.InternalName]);
                }
                rows.Add(new SharepointList.Row() { Values = values});
            }

            return new SharepointList() {Columns = cols, Rows = rows};
        }
开发者ID:rickythefox,项目名称:sharepoint-listitem-manager,代码行数:29,代码来源:SharepointService.cs

示例7: GetTaxonomyValueForLabel

        /// <summary>
        /// Retrieves a TaxonomyValue corresponding to a term label within a desired term store
        /// </summary>
        /// <param name="site">The current site</param>
        /// <param name="termStoreName">The term store name</param>
        /// <param name="termStoreGroupName">The group name</param>
        /// <param name="termSetName">The term set name</param>
        /// <param name="termLabel">The default label of the term</param>
        /// <returns>The taxonomy value or null if not found</returns>
        public TaxonomyValue GetTaxonomyValueForLabel(SPSite site, string termStoreName, string termStoreGroupName, string termSetName, string termLabel)
        {
            TaxonomySession session = this.taxManager.GetSiteTaxonomyCache(site, termStoreName).TaxonomySession;
            TermStore termStore = session.TermStores[termStoreName];

            return GetTaxonomyValueForLabelInternal(termStore, termStoreGroupName, termSetName, termLabel);
        }
开发者ID:GSoft-SharePoint,项目名称:Dynamite-2010,代码行数:16,代码来源:TaxonomyService.cs

示例8: Execute

        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, StringDictionary keyValues, out string output)
        {
            output = string.Empty;

            string url = Params["url"].Value.TrimEnd('/');
            bool force = Params["force"].UserTypedIn;
            string backupDir = Params["backupdir"].Value;

            SPList list = null;
            if (Utilities.EnsureAspx(url, false, false) && !Params["listname"].UserTypedIn)
                list = Utilities.GetListFromViewUrl(url);
            else if (Params["listname"].UserTypedIn)
            {
                using (SPSite site = new SPSite(url))
                using (SPWeb web = site.OpenWeb())
                {
                    try
                    {
                        list = web.Lists[Params["listname"].Value];
                    }
                    catch (ArgumentException)
                    {
                        throw new SPException("List not found.");
                    }
                }
            }

            if (list == null)
                throw new SPException("List not found.");

            Common.Lists.DeleteList.Delete(force, backupDir, list);

            return (int)ErrorCodes.NoError;
        }
开发者ID:GSoft-SharePoint,项目名称:PowerShell-SPCmdlets,代码行数:41,代码来源:DeleteList.cs

示例9: Execute

        /// <summary>
        /// Processes the content type.
        /// </summary>
        /// <param name="site">The site.</param>
        /// <param name="contentTypeName">Name of the content type.</param>
        /// <param name="verbose">if set to <c>true</c> [verbose].</param>
        /// <param name="updateFields">if set to <c>true</c> [update fields].</param>
        /// <param name="removeFields">if set to <c>true</c> [remove fields].</param>
        public static void Execute(SPSite site, string contentTypeName, bool updateFields, bool removeFields)
        {
            try
            {
                Logger.Write("Pushing content type changes to lists for '" + contentTypeName + "'");
                // get the site collection specified
                using (SPWeb rootWeb = site.RootWeb)
                {

                    //Get the source site content type
                    SPContentType sourceCT = rootWeb.AvailableContentTypes[contentTypeName];
                    if (sourceCT == null)
                    {
                        throw new ArgumentException("Unable to find Content Type named \"" + contentTypeName + "\"");
                    }
                    Execute(sourceCT, updateFields, removeFields);
                }
                return;
            }
            catch (Exception ex)
            {
                Logger.WriteException(new System.Management.Automation.ErrorRecord(new SPException("Unhandled error occured.", ex), null, System.Management.Automation.ErrorCategory.NotSpecified, null));
                throw;
            }
            finally
            {
                Logger.Write("Finished pushing content type changes to lists for '" + contentTypeName + "'");
            }
        }
开发者ID:GSoft-SharePoint,项目名称:PowerShell-SPCmdlets,代码行数:37,代码来源:PropagateContentType.cs

示例10: BuildFullMenuStructure

        private SiteMapNode BuildFullMenuStructure(SPWeb currentWeb)
        {
            Clear();

            SiteMapNode root = null;

            SPWeb webSite = SPContext.Current.Site.RootWeb;
            string relativeUrl = webSite.ServerRelativeUrl.ToString();

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite currentsite = new SPSite(webSite.Site.Url);
                SPWeb rootweb = currentsite.OpenWeb(relativeUrl);

                root = new SiteMapNode(this, rootweb.ID.ToString(), rootweb.ServerRelativeUrl, rootweb.Title);

                if (rootweb == currentWeb)
                {
                    SiteMapNode root2 = new SiteMapNode(this, "Root", "/", null);
                    AddNode(root2);

                    string cacheKey = rootweb.ID.ToString();
                    AddMenuToCache(cacheKey, root2);
                }

                foreach (SPWeb web in rootweb.Webs)
                {
                    SiteMapNode node = BuildNodeTree(web);
                    AddNode(node, root);
                }
            });

            return root;
        }
开发者ID:MohitVash,项目名称:TestProject,代码行数:34,代码来源:NCNewssiteTopNavigationProviderLevel2.cs

示例11: AddFileInfo

        private void AddFileInfo(SPItemEventProperties properties)
        {
            try
            {
                var url = properties.WebUrl + "/" + properties.AfterUrl;
                var fileName = properties.AfterUrl;

                using (var site = new SPSite(properties.Web.Site.ID))
                using (var web = site.RootWeb)
                {
                    var list = web.Lists[LogList.ListName];
                    var listItems = list.Items;

                    var item = listItems.Add();
                    item["Title"] = fileName;
                    item["URL"] = url;
                    item.Update();
                }

                ULSLog.LogDebug(String.Format("Added {0} to {1} list", url, LogList.ListName));
            }
            catch (Exception ex)
            {
                ULSLog.LogError(ex);
            }
        }
开发者ID:egil,项目名称:SPADD,代码行数:26,代码来源:FileChangedEventReceiver.cs

示例12: GetSpecifiedList

        public static SPList GetSpecifiedList(string listName)
        {
            // get fresh SPSite and SPWeb objects so they run in the correct context
            // depending on whether we have elevated privileges to view draft items
            // or not

            //Not sure if caching a good idea here or not...
            //object cacheData = HttpContext.Current.Cache["ListCache" + listName];

            //if (cacheData != null)
            //    return (SPList)cacheData;

            using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                if (listName.StartsWith("/"))
                {
                //    SPList lst=site.RootWeb.Lists[listName.Substring(1)];
                //    HttpContext.Current.Cache.Add("ListCache" + listName, lst, null, DateTime.Now.AddHours(12), System.Web.Caching.Cache.NoSlidingExpiration,
                //System.Web.Caching.CacheItemPriority.Default, null);
                    return site.RootWeb.Lists[listName.Substring(1)];
                }
                else
                {
                    using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
                    {
                    //    SPList lst = web.Lists[listName];
                    //    HttpContext.Current.Cache.Add("ListCache" + listName, lst, null, DateTime.Now.AddHours(12), System.Web.Caching.Cache.NoSlidingExpiration,
                    //System.Web.Caching.CacheItemPriority.Default, null);

                        return web.Lists[listName];
                    }
                }
            }
        }
开发者ID:infinitimods,项目名称:clif-sharepoint,代码行数:34,代码来源:SecurityHelper.cs

示例13: GetLastUpdateDate

        public static DateTime? GetLastUpdateDate()
        {
            DateTime? maxValue = null;

            try
            {
                SPWeb web;
                if (SPContext.Current != null)
                    web = SPContext.Current.Web;
                else
                    web = new SPSite("http://finweb.contoso.com/sites/PMM").OpenWeb();

                SPList objList = web.Lists.TryGetList(Constants.LIST_NAME_PROJECT_TASKS);

                SPQuery objQuery = new SPQuery();
                objQuery.Query = "<OrderBy><FieldRef Name='ModifiedOn' Ascending='False' /></OrderBy><RowLimit>1</RowLimit>";
                objQuery.Folder = objList.RootFolder;

                // Execute the query against the list
                SPListItemCollection colItems = objList.GetItems(objQuery);

                if (colItems.Count > 0)
                {
                    maxValue = Convert.ToDateTime(colItems[0]["ModifiedOn"]);
                }
            }
            catch (Exception ex)
            {

            }

            return maxValue;
        }
开发者ID:jgoodso2,项目名称:PMMP,代码行数:33,代码来源:TaskItemRepository.cs

示例14: Guardar

        internal static void Guardar(Contacto _contacto)
        {
            String webUrl = "http://sharepointser";

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (var site = new SPSite(webUrl))
                {
                    using (var web = site.OpenWeb())
                    {
                        SPListItemCollection list = web.Lists["Contactos"].Items;

                        SPListItem item = list.Add();
                        item["Title"] = _contacto.Nombre;
                        item["Identificacion"] = _contacto.Identificacion;

                        var allowUnsafeUpdates = web.AllowUnsafeUpdates;
                        web.AllowUnsafeUpdates = true;

                        item.Update();

                        web.AllowUnsafeUpdates = allowUnsafeUpdates;
                    }
                }
            });
        }
开发者ID:khriztianmoreno,项目名称:AddItemsSharepointPatternMVP,代码行数:26,代码来源:RepositorioContacto.cs

示例15: DeployIntranet

        public void DeployIntranet(SPSite site, Options options)
        {
            // pushing site model
            if (options.DeploySite)
            {
                var siteModel = new IntrSiteModel();

                this.DeploySiteModel(site, siteModel.GetSandboxSolutionsModel());
                this.DeploySiteModel(site, siteModel.GetSiteFeaturesModel());
                this.DeploySiteModel(site, siteModel.GetSiteSecurityModel());
                this.DeploySiteModel(site, siteModel.GetFieldsAndContentTypesModel());
            }

            // pushing root web model
            if (options.DeployRootWeb)
            {
                var rootWebModel = new IntrRootWebModel();

                this.DeployWebModel(site.RootWeb, rootWebModel.GetStyleLibraryModel());
                this.DeployWebModel(site.RootWeb, rootWebModel.GetModel());
            }

            // pushing 'How-tow' sub web
            if (options.DeployHowTosWeb)
            {
                var howTosWebModel = new IntrHowTosWebModel();

                this.DeployWebModel(site.RootWeb, howTosWebModel.GetModel());
            }
        }
开发者ID:maratbakirov,项目名称:2015_10_07_collab365demo,代码行数:30,代码来源:IntrStandardSSOMProvisionService.cs


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