Sunday, February 26, 2012

Command line error for adding content DB or delete content DB

Today I was playing with SharePoint content DBs for detaching and attaching. I mean changing the content DB of a Site Collection to a new Content DB (like restored copy of other environment like Prod).

So to do this, I was using STSADM commands like this:

stsadm -o deletecontentdb -url http://srisaihome:1099/sites/site2 -databasename wss_content_1099_1

I made this string in a notepad and coped to Commond Prompt Console and hit the Enter and I got the error like
“ Command Line Error”. However, I did'n’t do any mistake in writing the command. Here is the complete command I have written:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN>stsadm -o deletecontentdb -url http://srisaihome:1099/sites/site2 -databasename wss_content_1099_1

The weird thing is instead of copying the command from notepad If I type the command manually it works like a charm. Don’t be surprised, it’s weird but it’s true.  Not sure how many has experienced this, but thought of sharing this in my blog.

Sunday, February 12, 2012

Replace a WebPart with new one in SharePoint

using (SPSite spSiteTest = new SPSite(webURL))
           {
               SPFile file = null;
               using (SPWeb web = spSiteTest.OpenWeb())
               {
                   try
                   {
                       file = web.GetFile(webPageURL);
                       if (file.Level == SPFileLevel.Checkout)
                       {
                           file.CheckIn("Checkin before replace");
                           file.CheckOut();
                       }
                       else
                       {
                           file.CheckOut();
                       }
                       SPLimitedWebPartManager webPartMgr = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                       for (int k = 0; k < webPartMgr.WebParts.Count; k++)
                       {
                           System.Web.UI.WebControls.WebParts.WebPart wpOld = webPartMgr.WebParts[k];
                           if (string.Compare(wpOld.GetType().Name.Trim(), webPartName.Trim(), true) == 0)
                           {
                               //Read old webpart properties
                               string zoneID = webPartMgr.GetZoneID(wpOld);
                               string storageKey = webPartMgr.GetStorageKey(wpOld).ToString();
 
                               //create new webpart object            
                               MyNewWebPart wpNew = new MyNewWebPart();
                               wpNew.Title = wpOld.Title;// "Web Part Title";
                               wpNew.ChromeState = wpOld.ChromeState;// System.Web.UI.WebControls.WebParts.PartChromeState.Normal;
                               wpNew.ChromeType = wpOld.ChromeType;// System.Web.UI.WebControls.WebParts.PartChromeType.None;
 
                               webPartMgr.DeleteWebPart(wpOld);
                               //Add new webpart object to webparts collection     
                               webPartMgr.AddWebPart(wpNew, zoneID, 0);
                               file.Update();
                               web.Update();
                           }
                       }
                   }
                   catch (Exception ex)
                   {
                       if (file != null && file.Level == SPFileLevel.Checkout)
                       {
                           file.UndoCheckOut();
                       }
                   }
                   finally
                   {
                       if (file != null && file.Level == SPFileLevel.Checkout)
                       {
                           file.CheckIn("Added");
                       }
                       web.AllowUnsafeUpdates = false;
                   }
               }
 
           }

Get a List of Site Collections in a Web Application in SharePoint

            

               SPWebApplication webApp = SPWebApplication.Lookup(new Uri(“WebApplication URL”));

               foreach (SPSite site in webApp.Sites)
               {
                   radCmbSiteCollList.Items.Add(new RadComboBoxItem(site.Url));
                   site.Dispose();
               }

Get a List of Web Applications in a SharePoint Farm

Code to iterate through all the web applications in a SharePoint Farm         

              SPFarm farm = SPWebService.ContentService.Farm;
               SPWebApplicationCollection webAppColl = SPWebService.ContentService.WebApplications;
               if (webAppColl != null)
               {
                   foreach (SPWebApplication spWebApp in webAppColl)
                   {
                       lst.Items.Add(new ListItem(spWebApp.AlternateUrls[0].Uri.ToString()));
                   }
                   radCmbWebApplications.Items.Insert(0, new RadComboBoxItem(" -- Select a WebApplication -- ", "-1"));

               }

Thursday, October 20, 2011

Behave and Find My Site

Tip:

Assuming you already have Active Directory & Profile Database Synchronization working and your own My Site is flawlessly functioning, you may still get the User Not Found error while trying to assess your esteemed colleagues’ sites. The steps below saved my afternoon (and hopefully yours as well), and I still had daylight left on a warm afternoon for some surfing. Just kidding about the surfing; I don’t even swim.

1.     Open Central Administration.

2.     Under Application Management , click on Manage service applications.

3.     Click on the first User Profile Service.

4.     Under My Site Settings, click on Setup [sic] My Sites.

5.     Under Site Naming Format, change the default option to Domain and user name or User name.

6.     Head to nearest beach and ride the waves. Or learn swimming in some cases.

Access to XMLHttpRequest at 'from origin has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. .net core angular

Issue: The angular application was getting error from API that the origin has been blocked by CORS policy. Solution: Make sure that the...