Joseph Michael Pesch
VP Programming

Link Outlook Calendar to Sharepoint

by 26. November 2013 07:48

Tags:

C# App.Config Custom Dictionary Section to Store Simple Key/Value Pairs

by 4. November 2013 06:12

Below is a sample app.config using a custom dictionary section to store simple key/value pairs:

<configuration>
  <configSections>
    <section name="CustomDictionarySection" type="System.Configuration.DictionarySectionHandler"/>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <CustomDictionarySection>
    <add key="Key1" value="Value 1" />
    <add key="Key2" value="Value 2" />
    <add key="Key3" value="Value 3" />
  </CustomDictionarySection>
</configuration>
class Program
{
  static void Main(string[] args)
  {
    string key = "Key2";
    var section = (ConfigurationManager.GetSection("CustomDictionarySection") as System.Collections.Hashtable)
                .Cast<System.Collections.DictionaryEntry>()
                .Where(t => t.Key.ToString() == key);
    if (section.Count() > 0)
      Console.WriteLine(string.Format("Found section with key: {0} containing value: {1}", key, section.First().Value));
    else
      Console.WriteLine(string.Format("Could not find section with key: {0}", key));
    Console.Read();
  }
}

Tags:

C#

plUpload IO Error 2032

by 26. October 2013 12:58

Using plUpload I was getting IO Error 2032 on larger file uploads.  Two settings that seemed to be associated to this.  First, if I added the resize attribute (i.e. resize: { width: 1000, height: 1000, quality: 90 }, ); however, I didn't really want to resize and was concerned that could have browser dependencies that may not be well supported in all cases.  The second fix I actually opted for in this case was adding the chunk_size attribute.  The interesting issue I didn't figure out yet was adding as chunk_size: '1mb', worked even though my original attempt adding chunk_size: '64kb', failed.

Tags:

JQuery | plUpload

jQuery $(document).ready() Not Working with ASP.Net UpdatePanel PostBack

by 27. September 2013 20:21

When using jQuery and $(document).ready() event along with an ASP.Net UpdatePanel the $(document).ready() event will only fire on the initial page load and will not fire on subsequent AJAX postbacks via the UpdatePanel.  There are a couple of common solutions posted to deal with this (shown below).  My preference is the first option which seems cleaner and has proven more reliable for me.

Solution 1:  Wrap the $(document).ready() event inside a pageLoad() function since the AJAX postback will always fire the pageLoad() event function.

function pageLoad() {
  $(document).ready(function () {
    DoPageInitialization();
  });
}

Solution 2:  Add a reference to the PageRequestManager and register your function to the add_endrequest() event.

$(document).ready(function() {
  // Still needed as the PageRequestManager below only fires on the postback...
  DoPageInitialization();
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function() {
  // Secondary binding for all AJAX postbacks through the UpdatePanel
  DoPageInitialization();
});

function DoPageInitialization() {
  ... Document Ready Code Here ...
}


Here is a good post that goes into more details on both $(document).ready() and pageLoad()
http://encosia.com/document-ready-and-pageload-are-not-the-same/

Tags:

ASP.Net | JavaScript | JQuery

SharePoint WebPart Maintenance Page

by 5. September 2013 12:09

Issue with SharePoint is that the WebParts already in place on an existing page don't indicate what type of web part they actually are.  This is frustrating if it is not obvious what type of web part you are looking at.  In order to get a better view of the WebPart in question you can navigate to the WebPart Maintenance Page by entering a URL like this: http://yoursite/whatever/default.aspx?contents=1

Tags:

Sharepoint

C# Http Remote Page Post

by 30. August 2013 14:15
NameValueCollection Inputs = new NameValueCollection();
Inputs.Add("param1", "something");
Inputs.Add("param2", "somethingelse");
Http.RemotePost("http://google.com", Inputs);

using System.Collections.Specialized;
using System.Net;

public static class Http
{
  public static void RemotePost(string Url, NameValueCollection Inputs)
  {
    System.Web.HttpContext.Current.Response.Clear();
    System.Web.HttpContext.Current.Response.Write("<html><head>");
    System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", "form1"));
    System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", "form1", "post", Url));
    for (int i = 0; i < Inputs.Keys.Count; i++)
    {
      System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
    }
    System.Web.HttpContext.Current.Response.Write("</form>");
    System.Web.HttpContext.Current.Response.Write("</body></html>");
    System.Web.HttpContext.Current.Response.End();
  }
}

Tags:

C#

Sharepoint PDF Document Prompting User to Checkout when it Shouldn't

by 26. August 2013 15:54

We had issues with PDF documents on Sharepoint that were prompting the average "View Only" users to check-out the document.  If they actually attempted to check-out the document they could not; however, this was cofusing to the users.  The desired effect was to have the document open directly into the PDF viewer.  Below are some registry settings that seemed to clear this issue up in most cases.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Adobe\Adobe Acrobat\11.0\FeatureLockDown\cSharePoint]
"bDisableSharePointFeatures"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Adobe\Adobe Acrobat\10.0\FeatureLockDown\cSharePoint]
"bDisableSharePointFeatures"=dword:00000001

Tags:

Sharepoint

SQL DBCC ShrinkFile Not Working (i.e. Executes Successfully But File Does Not Shrink)

by 22. August 2013 12:41

When attempting to run "DBCC ShrinkFile" SQL command to shrink a transaction log file on a database that has replication enabled it may appear to have run successfully; however, the log file may not actually shrink.  To resolve this issue you can add a call to "EXEC sp_repldone" to allow the server to take action on the log file.  Below is a sample process that I have added to a nightly job to take place after the full DB backup executes.

use DBName;
go
alter database DBName set recovery simple;
go
exec sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0, @time = 0, @reset = 1
go
dbcc SHRINKFILE (DBName_log, 1);
go
alter database DBName set recovery full;
go

Tags:

SQL Server

Wordpress 404 Error When Using Permalinks /%postname%/

by 19. August 2013 20:43

Put the following content in the .htaccess file in the root folder:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

 Add Rewrite to web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <directoryBrowse enabled="false" />
    <defaultDocument>
      <files>
        <clear />
        <add value="index.php" />
      </files>
    </defaultDocument>
    <rewrite>
      <rules>
        <rule name="Main Rule" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php/{R:0}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Tags:

PHP | Wordpress

SMTP Hosting Service

by 28. July 2013 08:45

http://postmarkapp.com

 

Tags:

jQuery Document.Ready Doesn't Work with ASP.Net UpdatePanel

by 27. July 2013 21:47

When using an ASP.Net UpdatePanel you may need to use the PageRequestManager to bind functions that would otherwise be bound on the page load or jQuery Document.Ready function (see below).  Link to blog article on this topic: http://stackoverflow.com/questions/256195/jquery-document-ready-and-updatepanels 

$(document).ready(function() {
    // bind your jQuery events here initially
});

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(function() {
    // re-bind your jQuery events here
});

Tags:

ASP.Net | JQuery

A Guide to Designing and Building RESTful Web Services with WCF 3.5

by 22. July 2013 07:09

Excerpt from this article:  http://msdn.microsoft.com/en-us/library/dd203052.aspx

From the point of view of REST, a “real” Web service is a service designed to embrace the “Web” from the ground up. The Web has become the most successful distributed computing platform ever developed, thanks to years of investment and widespread usage. The Web platform includes concepts that you’re probably already familiar with like URIs, HTTP, and common data formats like XML, RSS/ATOM, and JSON. Ultimately, services that embrace these core concepts will immediately derive the valuable benefits they provide.

REST defines an architectural style based on a set of constraints for building things the “Web” way. REST is not tied to any particular technology or platform – it’s simply a way to design things to work like the Web. People often refer to services that follow this philosophy as“RESTful services.” In this whitepaper, we’ll cover the fundamental REST design principles and show you how to build RESTful services with Windows Communication Foundation (WCF), the WCF REST Starter Kit, and ADO.NET Data Services.

Tags:

ASP.Net | REST

Sharepoint 2010 Development on Windows 7 Virtual Machine

by 22. July 2013 07:01

Sharepoint 2010 Registry Entries

I recently installed a development machine with the necessary tools to perform SharePoint development on a Windows 7 64bit virtual machine.  The machine was then used as a master for a set of 7 virtual desktop developer workstations.  The issue; however, was that the inital intallations created several registry entries that referenced the original machine name.  This rendered the Sharepoint environment broken on all the virtual desktops (as each one had a different unique machine name).  To resolve this, I went back through the registry on the master and change the original machine name to "LOCALHOST" virtual name on all the following registry entries.  NOTE: The initial symptom manifest itself initially when opening the browser and attempting to browse to the local sharepoint site (in this case htt://localhost).  The page threw the follwing error: "Cannot connect to the configuration database."  Upon reviewing the log Sharepoint files (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS\...) I noticed the original machine name in the failed connection attempt log entry.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\LauncherSettings\LoadBalancerUrl
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Applications\c0e071e1-533e-457a-8a61-8a86a6b78dcd\Gather\Portal_Content\ContentSources\0\StartPages\0\URL
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Applications\c0e071e1-533e-457a-8a61-8a86a6b78dcd\Gather\Portal_Content\ContentSources\0\StartPages\1\URL
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Applications\c0e071e1-533e-457a-8a61-8a86a6b78dcd\ResourceManager\ (several entries)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Search\Applications\fd2e5092-25e3-46cf-8fc6-d62c85334b3d\Gather\Search\ContentSources\0\StartPages\0\URL
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Search\Applications\fd2e5092-25e3-46cf-8fc6-d62c85334b3d\ResourceManager\ (several entries)

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Secure\ConfigDB\dsn
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\CentralAdministrationURL

Tags:

Sharepoint | Virtual PC | Windows

Sharepoint 2013 Development Using Visual Studio 2012

by 16. July 2013 13:14

Here is a good article on setting up Visual Studio 2012 to allow development of Sharepoint 2013 applications.

http://blogs.msdn.com/b/timquin/archive/2013/01/22/setting-up-visual-studio-2012-for-sharepoint-2013-development-offline.aspx

Tags:

ASP.Net | Sharepoint

jQuery Invisible Dialog - Borderless with Transparent Background

by 1. July 2013 07:03

Here is some code to remove the titlebar from a jQuery dialog and also remove the borders and make the background transparent (effectively making the dialog itself invisible so only the actual content of the dialog is visible.

var $obj = $('selector');
$obj.dialog({ });
$obj.parents(".ui-dialog")
  .css("border", "0 none")
  .css("background", "transparent")
  .find(".ui-dialog-titlebar").remove();

Tags:

JQuery

Team Foundation Server (TFS) Building Project with External Assemblies

by 27. June 2013 08:47

This approach to fix the issue with using external assemblies (i.e. assemblies not in the project folder structure).  In this example the project references the "Encompass" assemblies from the "C:\Program Files (x86)\Encompass" folder.  I wanted to use the program file reference so it’s easy to upgrade SDK; however, Visual Studio Project always have relative paths which doesn’t get resolved in TFS Build.  To resolve this I have add new registry key for the Encompass folder path on the TFS build server so that it looks into this location when it compiles any project.  Now I don’t need to change the project file. 

Registry key: HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > .NET Framework > AssemblyFolders

Add new key (in this case "Encompass") and then update the "(default)" string value to be the path to the assemblies (in this case "C:\Program Files (x86)\Encompass").

Tags:

ASP.Net | Visual Studio | TFS

jQuery Dialog Disable Ok Button

by 24. June 2013 13:43

In some cases depending on the usage you may have a jQuery dialog open after the user clicks the Ok button; however, you may want to disable the button to prevent the user from double-clicking it.  Here are a couple of methods to achive this typ of behavior.  

Just disable the Ok button:

$(".ui-dialog-buttonpane button:contains('Ok')").attr("disabled", true).addClass("ui-state-disabled");

Remove all buttons and replace with a processing indicator:

$('#selector').dialog({
     title: 'Sample Dialog', 
     modal: true, 
     buttons: { 
       'Cancel': function() { $(this).dialog('close'); },
       'Ok': function() { $('.ui-dialog-buttonpane').html('<div style="width: 100%; text-align: center; padding: 20px; font-size: 20px; background: url(processing.gif) no-repeat;">Processing please wait...</div>'); 
     }
});

Tags:

JQuery

C# Windows Service to Log User Unlocking/Locking Computer

by 20. June 2013 08:09

Windows event logs will typically capture user login/logout activity; however, it does not capture user unlocking/locking their computer (which quite often is the more frequent activity).  This C# code will run as a Windows service and add Information entries into the Windows Application log accessible via the system Event Viewer.  Currently the code currently has an error in implementing "System.Security.Principal.WindowsIdentity.GetCurrent().Name" as an attempt to log the user name performing the activity; however, that is actually simply logging the user name that the Windows service is running as.  In a future update I plan to fix this issue and add the actual user name to the log entry.

 UserLockUnlockProfiler.zipx (41.86 kb)

Links regarding service interacting with user desktop:

https://stackoverflow.com/questions/5200341/capture-screen-on-server-desktop-session/12851218#12851218

https://stackoverflow.com/questions/5200341/capture-screen-on-server-desktop-session/12851218#12851218

Main Service Code:

using System;
using System.Diagnostics;
using System.Management;
using System.ServiceProcess;

namespace ULUPSvc
{
    public partial class ULUPSvc : ServiceBase
    {
        public ULUPSvc()
        {
            InitializeComponent();
            this.CanHandleSessionChangeEvent = true;
        }

        public void LogEvent(string msg)
        {
            msg += " " + DateTime.Now.ToString();
            ManagementScope ms = new ManagementScope("\\\\.\\root\\cimv2");
            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(ms, query);
            foreach (ManagementObject mo in searcher.Get())
            {
                msg += " (" + mo["UserName"].ToString() + ")";
            }
            EventLog eventLog = new EventLog();
            eventLog.Log = "Application";
            eventLog.Source = "ULUPSvc";
            eventLog.WriteEntry(msg, EventLogEntryType.Information);
        }

        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            switch (changeDescription.Reason)
            {
                case SessionChangeReason.SessionLogon:
                    LogEvent("Logon");
                    break;
                case SessionChangeReason.SessionLogoff:
                    LogEvent("Logoff");
                    break;
                case SessionChangeReason.SessionLock:
                    LogEvent("Lock");
                    break;
                case SessionChangeReason.SessionUnlock:
                    LogEvent("Unlock");
                    break;
            }
            base.OnSessionChange(changeDescription);
        }

        protected override void OnStart(string[] args)
        {
            // Make sure we have our application in the event log.
            if (!EventLog.SourceExists("ULUPSvc"))
                EventLog.CreateEventSource("ULUPSvc", "Application");
        }

        protected override void OnStop()
        {
            LogEvent("Stopping");
        }

    }

}

Tags:

C#

SQL Statement to View Connected Login Authentication Schema in Use (i.e. SQL, NTLM, Kerberos, etc.)

by 15. April 2013 12:45
The following is a SQL statement that will return a list of active connections and the login authentication schema being used by the connection.  This is useful in validating that connections are using the expected protocol. 
select 
s.session_id,
s.login_name,
s.host_name,
c.auth_scheme
from
sys.dm_exec_connections c
inner join
sys.dm_exec_sessions s
on c.session_id = s.session_id

Tags:

SQL Server

Uploadify Issue with IE9 Button Not Triggering Browser to Upload

by 13. April 2013 23:18
Suffering issue wtih IE9 and Uploadify where the button that usually triggers the browse for file dialog does nothing.  It works if I switch to compatability mode but does nothing in standard mode.  I found some updated code below that fixes the issue, just replace the existing code in the jquery.uploadify.js and jquery.uploadify.min.js files.
SWFUpload.prototype.getFlashHTML = function () {
  // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  var obj = ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">'].join(""),
params = [
'<param name="wmode" value="', this.settings.button_window_mode, '" />',
'<param name="movie" value="', this.settings.flash_url, '" />',
'<param name="quality" value="high" />',
'<param name="menu" value="false" />',
'<param name="allowScriptAccess" value="always" />',
'<param name="flashvars" value="', this.getFlashVars(), '" />'
].join("");
  if (navigator.userAgent.search(/MSIE/) > -1) {
    obj = ['<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="', this.movieName, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">'].join("");
    params += '<param name="src" value="' + this.settings.flash_url + '" />';
  }
  return [obj, params, '</object>'].join("");
};

Tags:

JavaScript