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


C# SPSite.OpenWeb方法代码示例

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


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

示例1: GetCurrentWeb

        /// <summary>
        /// Used to get current web. Because of anonymous access we cannot use SPContext.Current.Web directly
        /// </summary>
        /// <returns>SPWeb object</returns>
        public static SPWeb GetCurrentWeb()
        {
            SPWeb currentWeb = null;

            if (SPContext.Current.Web.CurrentUser != null)
            {
                currentWeb = SPContext.Current.Web;
            }
            else
            {
                SPWeb webSite = SPContext.Current.Site.RootWeb;

                string currentUrl = GetCurrentWebRelativeUrl();

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPSite site = new SPSite(webSite.Site.Url);

                    if (currentUrl == null || currentUrl == "")
                        currentWeb = webSite;
                    else
                    {
                        if (IsLayoutPage())
                            currentWeb = site.OpenWeb(currentUrl);
                        else
                            currentWeb = site.OpenWeb(currentUrl, false);

                        if (currentWeb.Exists == false || currentWeb == null)
                            currentWeb = webSite;
                    }
                });
            }
            return currentWeb;
        }
开发者ID:MohitVash,项目名称:TestProject,代码行数:38,代码来源:NCTopMenuHelper.cs

示例2: GetTargetWeb

        public SPWeb GetTargetWeb(SPSite site, string webUrl, Guid? webId)
        {
            if (webId.HasGuidValue())
            {
                return site.OpenWeb(webId.Value);
            }
            else if (!string.IsNullOrEmpty(webUrl))
            {
                var targetWebUrl = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = webUrl,
                    Context = site
                }).Value;

                // server relative URl, always
                targetWebUrl = UrlUtility.RemoveStartingSlash(targetWebUrl);
                targetWebUrl = "/" + targetWebUrl;

                var targetWeb = site.OpenWeb(targetWebUrl);

                return targetWeb;
            }

            // root web by default
            return site.RootWeb;
        }
开发者ID:maratbakirov,项目名称:spmeta2,代码行数:26,代码来源:LookupFieldModelHandler.cs

示例3: OnImported

        /// <summary>
        /// Called when [imported].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="eventArgs">The <see cref="Microsoft.SharePoint.Deployment.SPObjectImportedEventArgs"/> instance containing the event data.</param>
        public void OnImported(object sender, SPObjectImportedEventArgs eventArgs)
        {
            if (m_targetList == null && eventArgs.Type == SPDeploymentObjectType.List)
            {
                // Get the list for later processing.
                m_targetList = m_targetWeb.GetList(eventArgs.TargetUrl);
            }

            if (!m_retargetLinks)
                return;

            if (eventArgs.Type != SPDeploymentObjectType.ListItem)
                return;

            SPImport import = sender as SPImport;
            if (import == null)
                return;

            try
            {
                string url = eventArgs.SourceUrl; // This is not fully qualified so we need the user specified url for the site.
                using (SPSite site = new SPSite(m_sourceUrl))
                using (SPWeb web = site.OpenWeb(url, false))
                {
                    string targetUrl = m_targetSite.MakeFullUrl(eventArgs.TargetUrl);
                    SPListItem li = web.GetListItem(url);
                    int count = li.BackwardLinks.Count;
                    for (int i = count - 1; i >= 0; i--)
                    {
                        SPLink link = li.BackwardLinks[i];
                        using (SPWeb rweb = site.OpenWeb(link.ServerRelativeUrl, false))
                        {
                            object o = rweb.GetObject(link.ServerRelativeUrl);
                            if (o is SPFile)
                            {
                                SPFile f = o as SPFile;
                                f.ReplaceLink(eventArgs.SourceUrl, targetUrl);
                            }
                            if (o is SPListItem)
                            {
                                SPListItem l = o as SPListItem;
                                l.ReplaceLink(eventArgs.SourceUrl, targetUrl);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Links could not be retargeted for " + eventArgs.SourceUrl + "\r\n" + ex.Message);
            }
        }
开发者ID:GSoft-SharePoint,项目名称:PowerShell-SPCmdlets,代码行数:57,代码来源:ImportList.cs

示例4: 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

示例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: GetEmployeedetails

        internal Employee GetEmployeedetails(string name)
        {
            var empEntity = new Employee();
            using (var site = new SPSite(SPContext.Current.Site.Url))
            {
                using (var web = site.OpenWeb())
                {
                    SPUser user = web.CurrentUser;

                    hdnCurrentUsername.Value = user.Name;

                    SPListItemCollection currentUserDetails = GetListItemCollection(web.Lists[Utilities.EmployeeScreen], "Employee Name", name, "Status", "Active");
                    foreach (SPListItem currentUserDetail in currentUserDetails)
                    {
                        empEntity.EmpId = currentUserDetail[Utilities.EmployeeId].ToString();
                        empEntity.EmployeeType = currentUserDetail[Utilities.EmployeeType].ToString();
                        empEntity.Department = currentUserDetail[Utilities.Department].ToString();
                        empEntity.Desigination = currentUserDetail[Utilities.Designation].ToString();
                        empEntity.DOJ = DateTime.Parse(currentUserDetail[Utilities.DateofJoin].ToString());
                        empEntity.ManagerWithID = currentUserDetail[Utilities.Manager].ToString();
                        var spv = new SPFieldLookupValue(currentUserDetail[Utilities.Manager].ToString());
                        empEntity.Manager = spv.LookupValue;
                    }
                }
            }
            return empEntity;
        }
开发者ID:Praveenmanne,项目名称:LeaveApplication,代码行数:27,代码来源:ResignationFormUserControl.ascx.cs

示例7: Log

 public static void Log(Exception ex, string component)
 {
     try
     {
         SPSecurity.RunWithElevatedPrivileges(delegate
         {
             using (SPSite site = new SPSite(SPContext.Current.Site.RootWeb.Url + "/Admin"))
             {
                 using (SPWeb rootweb = site.OpenWeb())
                 {
                     rootweb.AllowUnsafeUpdates = true;
                     SPList logs = rootweb.Lists.TryGetList("Logs");
                     if (logs != null)
                     {
                         SPListItem item = logs.AddItem();
                         if (ex.Message.Length > 100)
                             item["Message"] = ex.Message.Substring(0, 100);
                         else
                             item["Message"] = ex.Message;
                         if (ex.StackTrace != null)
                             item["StackTrace"] = ex.StackTrace;
                         item["Component"] = component;
                         item.Update();
                         logs.Update();
                     }
                 }
             }
         });
     }
     catch { }
 }
开发者ID:ricardocarneiro,项目名称:wet-boew-sharepoint,代码行数:31,代码来源:LogEngine.cs

示例8: btnSave_Click

        protected void btnSave_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow itemRow in this.Gridview1.Rows)
            {
                TextBox txtCount = itemRow.FindControl("txtCounty") as TextBox;
                TextBox txtCountry = itemRow.FindControl("txtCountry") as TextBox;
                TextBox txtDate = itemRow.FindControl("txtDate") as TextBox;

                using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists.TryGetList(Consts.Lists.ScheduleHoliday.ListName);
                        if (list == null) continue;

                        SPListItem itemAdd = list.AddItem();
                        itemAdd[Consts.Lists.ScheduleHoliday.Fields.Title] = txtCount.Text;
                        itemAdd[Consts.Lists.ScheduleHoliday.Fields.Country] = txtCountry.Text;
                        itemAdd[Consts.Lists.ScheduleHoliday.Fields.Holidays] = Convert.ToDateTime(txtDate.Text);
                        itemAdd.Update();
                    }
                }
            }

            SetInitialRow();
        }
开发者ID:tarcisiocorte,项目名称:SharePoint-Sample-DropDownList-and-GridView,代码行数:26,代码来源:VisualWebPart1UserControl.ascx.cs

示例9: createNewDocumentLibrary

        public string createNewDocumentLibrary(SPSite site, string _web, string docLib)
        {
            //foreach (webs web_ in Enum.GetValues(typeof(webs)))
            //{
            try
            {
                bool webExist = webExists(site, _web);

                if (webExist == true)
                {

                    using (SPWeb web = site.OpenWeb(_web))
                    {
                        SPList list = web.Lists.TryGetList(docLib);
                        if (list == null)
                        {
                            SPListTemplateType tempType = SPListTemplateType.DocumentLibrary;
                            web.Lists.Add(docLib, null, tempType);
                            return docLib;
                        }
                    }
                }
                //}
            }
            catch { }
            return docLib;
        }
开发者ID:mareanoben,项目名称:Enogex,代码行数:27,代码来源:SPDocLibrary.cs

示例10: Write

        public override void Write(string source , string title , string content )
        {
            if (this._ElevatedPrivileges)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite elevatedsiteColl = new SPSite(_web.Site.ID))
                    {
                        using (SPWeb elevatedWeb = elevatedsiteColl.OpenWeb(_web.ID))
                        {
                            SPList list = this.EnsureList(elevatedWeb, _listName);
                            elevatedWeb.AllowUnsafeUpdates = true;

                            AddItem(list, source, title, content);
                        }
                    }
                });

            }
            else
            {
                SPList list = this.EnsureList(_web, _listName);
                AddItem(list, source, title, content);
            }
        }
开发者ID:porter1130,项目名称:C-A,代码行数:25,代码来源:SiteLogManager.cs

示例11: Main

        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://spf2010/sites/animus"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists.TryGetList("Wiadomości");
                    SPListItem item = list.Items.Cast<SPListItem>()
                        .FirstOrDefault();
                    if (item!=null)
                    {
                        string from = Get_Text(item, "colNadawca");
                        string to = Get_Text(item, "colOdbiorca");
                        string subject = item.Title;
                        string body = Get_Text(item, "colTrescHTML");
                        string newBody = MailManager.Tools.Get_InnerHTML(body, "HTML");
                        if (!string.IsNullOrEmpty(newBody))
                        {
                            body = newBody;
                        }

                        MailMessage message = new MailMessage(from, to , subject, body);
                        message.IsBodyHtml = true;

                        MailManager.MailManager.SendMailFromMessageQueue(item, message);
                    }
                }
            }
        }
开发者ID:fraczo,项目名称:STAFix24_Tools,代码行数:29,代码来源:Program.cs

示例12: TerminateWorkflow

        public static void TerminateWorkflow(int itemId, string listName, string wfName)
        {
            SPWeb currWeb = MOSSContext.Current != null ? MOSSContext.Current.Web : SPContext.Current.Web;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite osite = new SPSite(currWeb.Site.ID))
                {
                    using (SPWeb oweb = osite.OpenWeb(currWeb.ID))
                    {
                        SPListItem oitem = oweb.Lists[listName].GetItemById(itemId);
                        if (oitem != null)
                        {

                            foreach (SPWorkflow workflow in oitem.Workflows)
                            {
                                if (oweb.Lists[listName].WorkflowAssociations[workflow.AssociationId].Name.Equals(wfName)
                                    && !workflow.IsCompleted)
                                {
                                    oweb.AllowUnsafeUpdates = true;
                                    SPWorkflowManager.CancelWorkflow(workflow);
                                    oweb.AllowUnsafeUpdates = false;
                                    break;
                                }
                            }

                        }
                    }
                }
            });
        }
开发者ID:porter1130,项目名称:MOSSArt,代码行数:31,代码来源:MOSSWorkflow.cs

示例13: UpdateRecords

        private void UpdateRecords()
        {
            SPListItem item = SPContext.Current.ListItem;
            item["FileName"] = DataForm1.Submit();
            if (!string.IsNullOrEmpty(ctfComments.Value.ToString()))
            {
                    item["Comments"] = ctfComments.Value.ToString();
            }
            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,代码行数:28,代码来源:EditForm.aspx.cs

示例14: RetrieveWeb

        /// <summary>
        /// note: not threadsafe
        /// </summary>
        public static SPWeb RetrieveWeb(string siteUrl, RichTextBox rtbValidateMessage)
        {
            try
            {
                MainForm.DefInstance.Cursor = Cursors.WaitCursor;
                rtbValidateMessage.Clear();
                if (siteUrl.Trim() == "")
                {
                    SmartStepUtil.AddToRTB(rtbValidateMessage, "site URL is blank", Color.Red, 8, false, SmartStepUtil.enumIcon.red_x);
                    return null;
                }

                SPSite site;
                try
                {
                    site = new SPSite(siteUrl);
                }
                catch (Exception ex)
                {
                    SmartStepUtil.AddToRTB(rtbValidateMessage, "site not found: " + ex.Message + " ", Color.Red, 8, false, SmartStepUtil.enumIcon.red_x);
                    return null;
                }

                SPWeb web = site.OpenWeb();
                SmartStepUtil.AddToRTB(rtbValidateMessage, "site found: " + web.Url + " ", Color.Green, 8, false, SmartStepUtil.enumIcon.green_check);
                return web;
            }
            finally
            {MainForm.DefInstance.Cursor = Cursors.Default;}
        }
开发者ID:iasanders,项目名称:sushi,代码行数:33,代码来源:Util.cs

示例15: StartWorkflowButton1_Executed

        void StartWorkflowButton1_Executed(object sender, EventArgs e)
        {
            DataForm1.Update();
            ISharePointService sps = ServiceFactory.GetSharePointService(true);
            SPList list = sps.GetList(CAWorkFlowConstants.ListName.PODetails.ToString());
            SPListItem item = null;

            DataTable dtPODetails = this.DataForm1.dtPODetails;
            foreach (DataRow dr in dtPODetails.Rows)
            {
                item = list.Items.Add();
                item["RequestID"] = this.WorkFlowNumber;
                item["PONumber"] = dr["PONumber"];
                item["Amount"] = dr["Amount"];
                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,代码行数:34,代码来源:NewForm.aspx.cs


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