Esempio n. 1
0
        private void SwitchErrorsFile(bool onlyValidate)
        {
            try
            {
                rtbDisplay.Clear();

                SPWeb  web          = Util.RetrieveWeb(txtTargetSite.Text, rtbSiteValidateMessage);
                string pageNotFound = web.Site.WebApplication.FileNotFoundPage;
                if (string.IsNullOrEmpty(pageNotFound))
                {
                    AddToRtbLocal(" Current Error page: (there is currently no Error Page)", StyleType.bodyBlue);
                    return;
                }
                else
                {
                    AddToRtbLocal(" Current Error page: " + pageNotFound + "\r\n", StyleType.bodyBlue);

                    string             fileErr = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + @"\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\" + pageNotFound;
                    System.IO.FileInfo fi      = new System.IO.FileInfo(fileErr);
                    if (fi.Exists)
                    {
                        AddToRtbLocal(" Full Path: " + fi.FullName + "\r\n", StyleType.bodyBlue);
                    }
                    else
                    {
                        AddToRtbLocal(" Full Path: Can't find full path at: " + fi.FullName + "\r\n", StyleType.bodyBlue);
                    }
                }
                AddToRtbLocal("\r\n\r\n", StyleType.bodyBlack);

                if (web != null)
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(txtNewErrorPage.Text);
                    if (!fi.Exists)
                    {
                        AddToRtbLocal("New File not found '" + fi.FullName + "'", StyleType.bodyBlue);
                        return;
                    }
                    AddToRtbLocal("Copying new error page '" + fi.FullName + "' to Layouts directory. " + Util.V(onlyValidate) + "\r\n", StyleType.bodyBlue);
                    string fileErr = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + @"\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\" + fi.Name;
                    if (!onlyValidate)
                    {
                        fi.CopyTo(fileErr, true);

                        AddToRtbLocal("Setting WebApplication.FileNotFoundPage property\r\n", StyleType.bodyBlue);
                        Microsoft.SharePoint.Administration.SPWebApplication webApp = web.Site.WebApplication;
                        webApp.FileNotFoundPage = fi.Name;
                        webApp.Update();
                        AddToRtbLocal("\r\nsuccess\r\n", StyleType.bodyBlackBold);
                    }
                }
            }
            catch (Exception ex)
            {
                AddToRtbLocal(ex.Message, StyleType.bodyRed);
            }
        }
Esempio n. 2
0
        void btnRegister_Click(object sender, EventArgs e)
        {
            string AssemblyInfo;
            SPEventReceiverDefinitionCollection eventReceivers;
            Guid objSelectedRowID;

            try
            {
                // our code should be inserted here
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWeb ospWeb = SPContext.Current.Web;
                    Microsoft.SharePoint.Administration.SPWebApplication webApp = ospWeb.Site.WebApplication;
                    webApp.FormDigestSettings.Enabled = false;

                    SPEventReceiverType objType = (SPEventReceiverType)Enum.Parse(typeof(SPEventReceiverType), ddlInActiveEvents.SelectedValue);


                    AssemblyInfo = txtAssemblyName.Text + "," + GlobalConstants.VERSION + txtVersion.Text + "," + GlobalConstants.CULTURE + txtCulture.Text + "," + GlobalConstants.PUBLICKEYTOKEN + txtPublicKeyToken.Text;

                    //code to register the event
                    if (strEventType == GlobalConstants.LIST_EVENTTYPE)
                    {
                        objSPList      = SPContext.Current.Web.Lists[new Guid(listId)];
                        eventReceivers = objSPList.EventReceivers;
                        objSPList.EventReceivers.Add(objType, AssemblyInfo, txtClassName.Text);
                        objSPList.Update();
                    }
                    else
                    {
                        eventReceivers = SPContext.Current.Web.EventReceivers;
                        SPContext.Current.Web.EventReceivers.Add(objType, AssemblyInfo, txtClassName.Text);
                        SPContext.Current.Web.Update();
                    }

                    if (strActionType == GlobalConstants.ACTIONTYPE_EDIT_CLICK)
                    {
                        objSelectedRowID = new Guid(Convert.ToString(Page.Request.QueryString["GUID"]));

                        eventReceivers[objSelectedRowID].Delete();

                        //foreach (SPEventReceiverDefinition def in eventReceivers)
                        //{

                        //    if (Convert.ToString(def.Type) == Convert.ToString(Page.Request.QueryString[GlobalConstants.Query_String_EVENT_TYPE]) && Convert.ToString(def.Class) == Convert.ToString(Page.Request.QueryString[GlobalConstants.Query_String_CLASS]))
                        //    {
                        //        def.Delete();
                        //        break;
                        //    }

                        //}
                    }


                    this.Page.RegisterClientScriptBlock("CloseForm", "<script>javascript:window.close();window.opener.location.reload();</script>");
                    webApp.FormDigestSettings.Enabled = true;
                });
            }
            catch (Exception ex)
            {
                string strError = ex.Message.Replace("'", " ");
                Response.Write(strError);
            }
        }