<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>C:/Jeff/Code/Solutions</title><generator>Tumblr (3.0; @miscellanous)</generator><link>http://jeffwwelch.com/</link><item><title>SharePoint Show Internal Names Bookmarklet</title><description>&lt;p&gt;I don&amp;#8217;t know about you, but I get pretty annoyed when upon needing to know the Internal name of a SharePoint column&amp;#8230;navigating to the list settings page&amp;#8230;searching for the column link&amp;#8230;right clicking&amp;#8230;viewing the url&amp;#8230;stripping out the name&amp;#8230;and then, finally, URL decoding the result. &lt;/p&gt;
&lt;p&gt;So, I created a bookmarklet to append the name to the link.&lt;/p&gt;
&lt;p&gt;Drag this &lt;a href="javascript:(function()%7Bvar%20jqueryJsElement=document.createElement(%22script%22);var%20jquerySrc=document.createAttribute(%22src%22);jquerySrc.nodeValue=%22http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js%22;jqueryJsElement.setAttributeNode(jquerySrc);document.body.appendChild(jqueryJsElement);%24(%22%5Bid%5E="&gt;Show Internal Names&lt;/a&gt; link to your bookmarks and click when you need to know.&lt;/p&gt;
&lt;h2&gt;Before&lt;/h2&gt;
&lt;p&gt;&lt;img src="http://25.media.tumblr.com/tumblr_m3rcfcTC5B1rvgqt5o1_500.png"/&gt;&lt;/p&gt;
&lt;h2&gt;After&lt;/h2&gt;
&lt;p&gt;&lt;img src="http://24.media.tumblr.com/tumblr_m3rci57d1k1rvgqt5o1_500.png"/&gt;&lt;/p&gt;
&lt;h2&gt;Here&amp;#8217;s the code&lt;/h2&gt;
&lt;pre&gt;javascript: (function () {

    //load 1.7.2 jquery
    j = document.createElement("script");
    s = document.createAttribute("src");
    s.nodeValue =
	    "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js";
    j.setAttributeNode(s);
    document.body.appendChild(j);

    //find the anchors who's id begins with "LinkEditField"
    //	for each, extract the "Field" url param and show it 
    //	next to the anchor of the format:
    //		&lt;a href="http://..."&gt;Display Name (Internal Name)&lt;/a&gt;
    $("[id^='LinkEditField']").each(function () {
        h = $(this).attr("href");
        $(this).append("  (" +
            unescape(h.substring(h.indexOf("&amp;amp;Field=") + 7)) +
            ")");
    });
})()
&lt;/pre&gt;</description><link>http://jeffwwelch.com/post/22715052861</link><guid>http://jeffwwelch.com/post/22715052861</guid><pubDate>Wed, 09 May 2012 09:56:34 -0400</pubDate></item><item><title>Get a list of list columns with the SiteData.GetList Web Service Method</title><description>&lt;p&gt;If you need to get a list of all fields in a list with their Internal name, static name, and type&amp;#8230;AND you must do this with a web service, try the &lt;a href="http://msdn.microsoft.com/en-us/library/ms774793%28v=office.12%29.aspx"&gt;SiteData.GetList Web Service Method&lt;/a&gt;.  Here&amp;#8217;s an example:&lt;/p&gt;
&lt;pre&gt;SiteDataService.SiteData siteDataService = new SiteDataService.SiteData();
siteDataService.Url = "http://[web site]/_vti_bin/SiteData.asmx";
siteDataService.UseDefaultCredentials = true;
SiteDataService._sListMetadata metaData = null;
SiteDataService._sProperty[] fields = null;

siteDataService.GetList("Opportunities", out metaData, out fields);

XmlDocument doc = new XmlDocument();
XmlNode allFieldsNode = doc.CreateElement("AllFields");
foreach (SiteDataService._sProperty field in fields)
{
    XmlNode fieldNode = doc.CreateElement("Field");
    XmlNode nameNode = doc.CreateElement("Name");
    nameNode.InnerText = field.Name;
    XmlNode titleNode = doc.CreateElement("Title");
    titleNode.InnerText = field.Title;
    XmlNode typeNode = doc.CreateElement("Type");
    typeNode.InnerText = field.Type;
    fieldNode.AppendChild(nameNode);
    fieldNode.AppendChild(titleNode);
    fieldNode.AppendChild(typeNode);
    allFieldsNode.AppendChild(fieldNode);
}
doc.AppendChild(allFieldsNode);

WriteToFile(@"C:\SiteData.raw.xml", allFieldsNode);
&lt;/pre&gt;</description><link>http://jeffwwelch.com/post/22265808499</link><guid>http://jeffwwelch.com/post/22265808499</guid><pubDate>Wed, 02 May 2012 14:47:11 -0400</pubDate><category>SharePoint</category></item><item><title>Why Am I Getting Permission Errors When RunWithElevatedPrivileges ?</title><description>&lt;p&gt;Shouldn&amp;#8217;t &amp;#8220;RunWithElevatedPrivilages&amp;#8221; allow you to do just that?  Well yes, and it does, but sometimes you can be carrying over some underprivileged objects.&lt;/p&gt;
&lt;p&gt;Since &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges%28v=office.12%29.aspx"&gt;RunWithElevatedPrivileges&lt;/a&gt; allows you to execute some code inline through the power of &lt;a href="http://msdn.microsoft.com/en-us/library/0yw3tz5k%28v=vs.80%29.aspx"&gt;Anonymous Methods&lt;/a&gt;, and since anonymous methods allow you to access objects outside of that method, we need to be mindful of the nature of those object instances and what skeletons they may be hiding in their permissions.  Take, for example, a recent run-in that I&amp;#8217;ve had with this problem.&lt;/p&gt;
&lt;p&gt;I needed to give the ability to add a user to a list item, through a custom ASP.NET form.  This works fine if the user being added is already on the site, however, if the user doesn&amp;#8217;t currently live there, you have to &amp;#8220;add&amp;#8221; them first by calling &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.ensureuser%28v=office.12%29.aspx"&gt;EnsureUser&lt;/a&gt; .  Because it requires higher permissions than what you would normally give a user to your site, EnsureUser should be run with elevated privileges (refer to &lt;a href="http://geek.hubkey.com/2008/01/searching-for-users-or-groups-using.html"&gt;this article&lt;/a&gt;) Check out the code I was using initially:&lt;/p&gt;
&lt;pre&gt;...
SPSecurity.RunWithElevatedPrivileges(delegate()
{
    SPUser userInfo = item.Web.EnsureUser(inputHidden.Value);
    item["MyUserField"] = new SPFieldUserValue(item.Web, userInfo.ID, userInfo.LoginName);
});
&lt;/pre&gt;
&lt;p&gt;The &amp;#8220;&amp;#8230;&amp;#8221; indicates some other code where the &amp;#8220;item&amp;#8221; SPList item is instantiated. &lt;strong&gt;Important, to note, this happens OUTSIDE of the RunWithElevatedPrivileges delegate&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;When the code runs, a user would get the dreaded &amp;#8220;Access Denied&amp;#8221; message indicating that they and not the app pool user (which is the user running the code inside RunWithElevatedPrivileges) were in fact trying to EnsureUser. Why would the app pool user get a permissions error?  Especially now?  The answer is found in this &lt;a href="http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/71a41096-ddbf-43a2-9de8-f2d303a3223b"&gt;MSDN message board answer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Essentially what&amp;#8217;s happening here is, the &lt;strong&gt;item&lt;/strong&gt; object instance is created as the user running the page. Then, even though the code hands that data off to a higher account, that object still can&amp;#8217;t perform restricted operations because it still has permissions residue from the last time it was used. Ah ha! So here&amp;#8217;s my updated code:&lt;/p&gt;
&lt;pre&gt;string webUrl = item.Web.Site.Url;
Guid webId = item.Web.ID;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(webUrl))
    {
        using (SPWeb web = site.OpenWeb(webId))
        {
            web.AllowUnsafeUpdates = true;

            SPUser userInfo = web.EnsureUser(inputHidden.Value);
            item[inputHidden.Attributes["__sharepointfieldstaticname"]] = new SPFieldUserValue(web, userInfo.ID, userInfo.LoginName);

            web.AllowUnsafeUpdates = false;
        }
    }
});
&lt;/pre&gt;
&lt;p&gt;As you can see, I create new site and web instances for use inside the delegate instead of reusing the one from the &lt;strong&gt;item&lt;/strong&gt; object. As a result, the user is added in time to add them to the item.&lt;/p&gt;</description><link>http://jeffwwelch.com/post/22124788596</link><guid>http://jeffwwelch.com/post/22124788596</guid><pubDate>Mon, 30 Apr 2012 11:23:00 -0400</pubDate><category>SharePoint MOSS</category></item><item><title>If your simple SharePoint Designer workflow won't start, look at this.</title><description>&lt;p&gt;So I have been building some custom SharePoint Designer activities, and testing them on a Virtual Machine of mine. I log into that machine as the System Administrator, and of course browse SharePoint. I noticed that for even the most simplest workflow, while I could start it manually, it wouldn&amp;#8217;t start automatically no matter what. I searched through the logs and found this:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;#8220;Declarative workflows cannot automatically start if the triggering action was performed by System Account. Canceling workflow auto-start.&amp;#8221;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Well, there ya go. If you are logged in as the System Administrator, workflows won&amp;#8217;t automatically kick off. Simple fix.&lt;/p&gt;</description><link>http://jeffwwelch.com/post/11141295782</link><guid>http://jeffwwelch.com/post/11141295782</guid><pubDate>Fri, 07 Oct 2011 11:07:51 -0400</pubDate></item><item><title>How To Change An InfoPath View With K2 Blackpearl</title><description>&lt;p&gt;&lt;a href="https://skydrive.live.com/self.aspx/jeffwwelch.com/How%20To%20Set%20InfoPath%20View%20In%20K2%20Process.zip?cid=4d7454d78c5a8628"&gt;Download Code&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A classic K2 Workflow goes like this:&lt;/p&gt;
&lt;p&gt;An HR Department wants to automate their Leave Request Process.  It is currently a paper based, manual endeavor which has led to some frustrating situations.  They have been told that hosting this process in K2 will alleviate many of their issues. &lt;/p&gt;
&lt;p&gt;In addition to simply building the workflow in K2, the HR Department wants entire submission stored in a SharePoint Form Library for future use.  So, how do we do that?&lt;/p&gt;
&lt;p&gt;Firstly, lets assume that this is what the workflow looks like:&lt;/p&gt;
&lt;p&gt;&lt;img height="325" width="473" src="https://xhzljq.blu.livefilestore.com/y1p3iM9wIlwz1NJxEGPDjj_IpDcUhczvH3ddCHOGgDIebVgTq8tutYpQYJHPrrx4JmG3kQ-8TEe6a9A0AcMduc3upJ6uw6xgbVc/Workflow%20Diagram.png?psid=1" align="middle" alt="Workflow Diagram"/&gt;&lt;/p&gt;
&lt;p&gt;Now let&amp;#8217;s say that the requirement is to store the request in some &amp;#8220;Approved&amp;#8221; library if HR approves and &amp;#8220;Rejected&amp;#8221; if they reject.  Here&amp;#8217;s how to do that.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1&lt;/strong&gt;  Create your form libraries.  I named mine &amp;#8220;Approved Leave Requests&amp;#8221; and &amp;#8220;Rejected Leave Requests&amp;#8221; respectively.&lt;/p&gt;
&lt;p&gt;2  Create two new views in the form.  The first view shows the data of an approved form, the other for the rejected.&lt;/p&gt;
&lt;p&gt;Approved:&lt;/p&gt;
&lt;p&gt;&lt;img height="144" width="429" src="https://xhzljq.blu.livefilestore.com/y1pCftxXChsOuGmTUzpAt2uAgXmzN1aCZodZ5tgfe0d6wJ86fjn1YUjC5MEpKKW2LeFAR4ca6tJXqwlbS6TUjNxTStj6Rq92PjS/Approved%20Form.png?psid=1" align="middle" alt="Approved Form"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt; Rejected:&lt;/p&gt;
&lt;p&gt;&lt;img height="144" width="437" src="https://xhzljq.blu.livefilestore.com/y1p0XKJNfnLebzNBkCSog5XGgbmXOoZNpQ8FWeuSzlD0Z4m3FXKMglHURpjfmsmSi2yRz6ZdTvX9rYkLJYbE-4DKkiJqC1T-IAC/Rejected%20Form.png?psid=1" align="middle" alt="Rejected Form"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt; 3  Use the SharePoint Documents event inside the workflow to create a new document in each of the libraries.&lt;/p&gt;
&lt;p&gt;Step 1:  On event name/action step, select to Upload from a K2 field.&lt;/p&gt;
&lt;p&gt;&lt;img height="537" width="590" src="https://xhzljq.blu.livefilestore.com/y1psjmj6BLri70LV4DnCGw6Xqpz_YcCfLsR2zjS1hCB3N2m2WDF3JvpAqbTpMHihtZQiX92LNJMbVJoPCN4ahPoeo3Xz_W-5BFA/SharePoint%20Documents%20Step1.png?psid=1" alt="SharePoint Documents Step 1"/&gt;&lt;/p&gt;
&lt;p&gt;Step 2:  Drag the root node of the InfoPath XML into the input field marked as &amp;#8220;K2 Field&amp;#8221; &lt;/p&gt;
&lt;p&gt;&lt;img height="406" width="597" src="https://xhzljq.blu.livefilestore.com/y1pWp1Ca9wu22iTbPQiesc02Y1B-RM5FEyqGXIx73AsgWI1qPCtVkCVnvaW_Bq6jpCnkLFbnpiLyXmMPwuct3UpqNSGxwBLjhat/SharePoint%20Documents%20Step2.png?psid=1" align="middle" alt="SharePoint Documents Step 2"/&gt;&lt;/p&gt;
&lt;p&gt;Step 3:  Choose the appropriate site, library, and content type (if necessary) for this upload.  For the document name, I&amp;#8217;m using the process folio.  You can use whatever you want as long as you don&amp;#8217;t forget to type &amp;#8220;.xml&amp;#8221; after it.&lt;/p&gt;
&lt;p&gt;&lt;img height="537" width="590" src="https://xhzljq.blu.livefilestore.com/y1psjmj6BLri71k0uiPCC6SANGcgZqj3a3AgiL7Zc-VvG8VdUS2VQXxnpMZHFXEHNhgCNjIyFDaytNhGlT8VtIzSm2vt_CG1UMS/SharePoint%20Documents%20Step3.png?psid=1" align="middle" alt="Document Event Step 3"/&gt;&lt;/p&gt;
&lt;p&gt;4  Set the view of the InfoPath document, before you upload it.  Use the Data event to accomplish this.&lt;/p&gt;
&lt;p&gt;Step 1:  Select Transfer Data&lt;/p&gt;
&lt;p&gt;&lt;img height="537" width="590" src="https://xhzljq.blu.livefilestore.com/y1p5ZTgb79VODsk2uOO5nwfUgy57UzZK3J9vBUJkZTf2TmxN-nLKXcw3_4V-k1TGxMSdBAnsTyW-eg_kCOLN04Q5iBWP4eeIvWh/Data%20Event%20Step1.png?psid=1" align="middle" alt="Data Event Step 1"/&gt;&lt;/p&gt;
&lt;p&gt;Step 2:  Set the &amp;#8220;DocumentView&amp;#8221; field to &amp;#8220;Leave Request Approved&amp;#8221; and &amp;#8220;Leave Request Rejected&amp;#8221; respectively.&lt;/p&gt;
&lt;p&gt;&lt;img height="386" width="600" src="https://xhzljq.blu.livefilestore.com/y1p5ZTgb79VODsO_kmUhbgVsjTQnFDunm72-RkVxIzuuGGYsJFnxaAuiTF6C-6-uGJ3JGh62NaYuS_flD-DEZ5s58gm0zRyRBLD/Data%20Event%20Step2.png?psid=1" align="middle" alt="Data Event Step 2"/&gt;&lt;/p&gt;&lt;p&gt;And that&amp;#8217;s it.  You&amp;#8217;ll see that when the document is created, and viewed, the Approved or Rejected view will be shown accordingly.&lt;/p&gt;</description><link>http://jeffwwelch.com/post/11117190706</link><guid>http://jeffwwelch.com/post/11117190706</guid><pubDate>Thu, 06 Oct 2011 19:13:00 -0400</pubDate></item><item><title>Getting and Setting Workflow Variables From A Custom Activity, Windows Workflow Foundation</title><description>&lt;p&gt;When building workflows you inevitably get into a situation where the built in activities just don&amp;#8217;t cut it.  In that case, you&amp;#8217;ll build a custom activity to do whatever intricate business logic that you need.  In the process of creating an activity of this nature, you&amp;#8217;ll add some properties, Dependency Properties, that allow the workflow to pass data to the activity.  What happens, however, when you want to go in the opposite direction?  How do you read or change the value of a workflow variable?  Well these two functions will get you there.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;GetValueOfWorkflowVariable:&lt;/b&gt;&lt;/p&gt;
&lt;pre&gt;public static object GetValueOfWorkflowVariable(Activity activity, string valueName)
{
   object value = null;
   if (activity != null)
   {
      try
      {
         ActivityBind workflowActivityBind = new ActivityBind();
         workflowActivityBind.Name = activity.Name;
         workflowActivityBind.Path = valueName;
         value = workflowActivityBind.GetRuntimeValue(activity);
      }
      catch
      { }
      if (value == null)
         value = GetValueOfWorkflowVariable(activity.Parent, valueName);
      }
      return value;
   }
}&lt;/pre&gt;
&lt;p&gt;In order to get the value of a workflow variable, you have to create an ActivityBind object.  With that, you can pass the name of an activity and then the Path or name of the variable you want to access.  Since a workflow is just a type of activity (a SequentialWorkflowActivity to be exact), this will work. &lt;/p&gt;
&lt;p&gt;However, getting the value of a variable from an activity isn&amp;#8217;t the hard part.  The hard part is finding what activity is the actual workflow activity.  Since we don&amp;#8217;t have easy access to the workflow itself from inside an activity, we can only reference it&amp;#8217;s parent, and the parent could be a Sequence Activity, While Activity, or any other kind of composite activity.  So in this code, if we can&amp;#8217;t find the variable in question, we search the parent.  We keep traversing up the tree until we find a matching variable.  If, we get all the way to the top (or the activity is null), and we still haven&amp;#8217;t found it, we simply return null.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Here&amp;#8217;s an example of how you use it:&lt;/b&gt;&lt;/p&gt;
&lt;pre&gt;String activityValue = "";
activityValue = GetValueOfWorkflowVariable(this.Parent, "ActivityValue").ToString();&lt;/pre&gt;
&lt;p&gt;In this example, I pass this.Parent as the activity because I know this activity isn&amp;#8217;t the workflow itself&amp;#8230;so maybe its parent is.&lt;/p&gt;
&lt;p&gt;Setting the value of a workflow variable is very much the same with a little less code.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;SetValueOfWorkflowVariable:&lt;/b&gt;&lt;/p&gt;
&lt;pre&gt;public static void SetValueOfWorkflowVariable(Activity activity, string valueName, object value)
{
   if (activity != null)
   {
      try
      {
         ActivityBind workflowActivityBind = new ActivityBind();
         workflowActivityBind.Name = activity.Name;
         workflowActivityBind.Path = valueName;
         workflowActivityBind.SetRuntimeValue(activity, value);
      }
      catch
      {}
      SetValueOfWorkflowVariable(activity.Parent, valueName, value);
   }
}&lt;/pre&gt;
&lt;p&gt;Again we create an ActivityBind object and traverse the tree until we successfully set the value of the variable.  If for some reason we can&amp;#8217;t find it, we exit the function with no error.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Here&amp;#8217;s an example of how to use it:&lt;/b&gt;&lt;/p&gt;
&lt;pre&gt;String activityValue = "Some Value";
SetValueOfWorkflowVariable(this.Parent, "ActivityValue");&lt;/pre&gt;
&lt;p&gt;And that&amp;#8217;s it, now whenever you need access to some workflow variable either to read or change, you need only include these methods and call them.&lt;/p&gt;</description><link>http://jeffwwelch.com/post/109592455</link><guid>http://jeffwwelch.com/post/109592455</guid><pubDate>Mon, 18 May 2009 14:30:00 -0400</pubDate><category>Windows Workflow Foundation</category><category>WF</category></item></channel></rss>

