February 24, 2012

SharePoint Designer Workflow to create Pages in Pages Library


Issue#1 : The workflow could not create the list item
1. Create a page with the content type you want to create via Workflow normally
Note: Go to Pages Library --> Add your custom content type --> Documents --> New Document --> Select your content type.
2. With SharePoint Designer open the directory, highlight the file you created and choose export - then save it to somewhere on your computer
3. Go back to the List you will create the items in, and under "List Settings" click on the content type in question then choose "Advanced Settings"
4. Choose "Upload a new document template" browse to the saved file and upload it
5. Now you can create the WF in SPD - the "Path and Name" can be set normally - no need for adding relative paths, if you set it to "Something" it will create it as "Something.aspx" under the wiki library for example - content type should be of course the one we modified.

Issue#2 : The workflow could not check in the list item. Make sure the item is already checked out.

February 23, 2012

Preventing provisioning duplicate Web Parts instances on Feature reactivation

http://blog.mastykarz.nl/preventing-provisioning-duplicate-web-parts-instances-on-feature-reactivation/


using (SPSite site = new SPSite("http://sharepoint"))
{
  SPList list = site.GetCatalog(SPListTemplateType.MasterPageCatalog);
  SPListItemCollection items = list.Items;
  List<string> webParts = new List<string>();

  // find the right Page Layout
  foreach (SPListItem item in items)
  {
    if (item.Name.Equals("CustomPageLayout.aspx",
      StringComparison.CurrentCultureIgnoreCase))
    {
      SPFile file = item.File;
      // get the Web Part Manager for the Page Layout
      SPLimitedWebPartManager wpm =
        file.GetLimitedWebPartManager(PersonalizationScope.Shared);
      // iterate through all Web Parts and remove duplicates
      while (wpm.WebParts.Count > 0)
      {
        StringBuilder sb = new StringBuilder();
        XmlWriterSettings xws = new XmlWriterSettings();
        xws.OmitXmlDeclaration = true;
        XmlWriter xw = XmlWriter.Create(sb, xws);
        System.Web.UI.WebControls.WebParts.WebPart wp =
          wpm.WebParts[0];
        wpm.ExportWebPart(wp, xw);
        xw.Flush();
        string md5Hash = getMd5Hash(sb.ToString());
        if (webParts.Contains(md5Hash))
          wpm.DeleteWebPart(wp);
        else
          webParts.Add(md5Hash);
      }
    }
  }
}

If Statement in One Line

($myvalue == 10) ? "the value is 10": "the value is not 10";

Document Library Event receiver


 if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null && properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
{
//This is when the update event is triggered by check-in.
}
else
{
//This is triggered by events other than check-in action.
}

February 22, 2012

ERROR OCCURRED IN DEPLOYMENT STEP ‘ACTIVATE FEATURES’: OPERATION IS NOT VALID DUE TO THE CURRENT STATE OF THE OBJECT.

1. Close Visual Studio
2. IISRESET

Trying to use an SPWeb object that has been closed or disposed and is no longer valid.

VisualWebPart - Visual WebPart - Custom and EditPart Properties

http://blog.concurrency.com/sharepoint/create-a-custom-web-part-for-sharepoint-2010/

private string customTextProp = "";

[WebBrowsable(true),
Category("Miscellaneous"),
Personalizable(PersonalizationScope.Shared),
WebDisplayName("Enter some text")]
public string CustomTextProp 

get{return customTextProp;}
set{customTextProp = value;
}


protected override void CreateChildControls()
{
   MyWebPartUserControl control = Page.LoadControl(_ascxPath) as MyWebPartUserControl;
   if (control != null)
      control.WebPart = this;
      Controls.Add(control);
   }
}



In UserControl.cs file
public MyWebPart WebPart { get; set; }

In 2007:

      Button btn = new Button();


        protected override void CreateChildControls()
        {
            btn.Text = "Set the Property";
            btn.Click += new EventHandler(btn_AddLink);
            this.Controls.Add(btn);
        }


        private void btn_AddLink(Object sender, EventArgs e)
        {
            btn.Text = "Changed Text";
        }

February 15, 2012

February 08, 2012

CWQP Additional Filter

http://blogs.msdn.com/b/ecm/archive/2010/05/14/what-s-new-with-the-content-query-web-part.aspx

Note: PageFieldValue should be a part of the content type where you are trying to filter, otherwise you get
"Site or List Column 'ColumnName' Doesnot consist"

And yeah, it supports multi valued managed metadata column too.

SonarQube with Jenkins Setup using Docker Images

https://funnelgarden.com/sonarqube-jenkins-docker/  https://medium.com/@hakdogan/an-end-to-end-tutorial-to-continuous-integration-and-con...