Joseph Michael Pesch
VP Programming

C# Auto-Rotate Image Based on Camera Rotation Exif Data

by 27. December 2013 08:14

This method uses ExifExtractor code referenced below from CodeProject.com.

public static Bitmap AutoRotateImage(Bitmap bmp)
{
  // Get source from: http://www.codeproject.com/KB/graphics/exifextractor.aspx?fid=207371
  var exif = new EXIFextractor(ref bmp, "n");
  switch (int.Parse(exif["Orientation"].ToString()))
  {
    case 1:
      bmp.RotateFlip(RotateFlipType.RotateNoneFlipNone);
      break;
    case 2:
      bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
      break;
    case 3:
      bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
      break;
    case 4:
      bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
      break;
    case 5:
      bmp.RotateFlip(RotateFlipType.Rotate90FlipX);
      break;
    case 6:
      bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
      break;
    case 7:
      bmp.RotateFlip(RotateFlipType.Rotate270FlipX);
      break;
    case 8:
      bmp.RotateFlip(RotateFlipType.Rotate270FlipNone);
      break;
    default:
      bmp.RotateFlip(RotateFlipType.RotateNoneFlipNone);
      break;
  }
  return bmp;
}

 

Tags:

C#

Entity Framework Error Saving - New transaction is not allowed because there are other threads running in the session

by 1. December 2013 14:12

When running inside a foreach() statement this error will occur unless you convert the Entity objects into a List.

// Original code that errors:
myFlickr = FlickrAuthentication();
using (FlickrPicsModel.FlickrPicsEntities dbx = new FlickrPicsModel.FlickrPicsEntities())
{
  foreach (FlickrPicsModel.Pic pic in dbx.Pics.Where(t => t.ProcessDate.Value >= MinDate &&
    t.FlickrPhotoId == null))
  {
    pic.FlickrPhotoId = myFlickr.UploadPicture(string.Concat(pic.FilePath, @"\", pic.FileName)
      , pic.FlickrTags, pic.FlickrTags, pic.FlickrTags + ",CS-" + pic.CheckSum.ToString());
    dbx.SaveChanges();
  }
}

// New code converting to IList:

myFlickr = FlickrAuthentication();
using (FlickrPicsModel.FlickrPicsEntities dbx = new FlickrPicsModel.FlickrPicsEntities())
{
  foreach (FlickrPicsModel.Pic pic in dbx.Pics.Where(t => t.ProcessDate.Value >= MinDate &&
    t.FlickrPhotoId == null).ToList())
  {
    pic.FlickrPhotoId = myFlickr.UploadPicture(string.Concat(pic.FilePath, @"\", pic.FileName)
      , pic.FlickrTags, pic.FlickrTags, pic.FlickrTags + ",CS-" + pic.CheckSum.ToString());
    dbx.SaveChanges();
  }
}

Error Message: New transaction is not allowed because there are other threads running in the session.

Tags:

Visual Studio Open Database Error: Failed to Generate a User Instance of SQL Server

by 29. November 2013 12:48

Running SQLExpress and trying to open database from Visual Studio.  In my case I originally had SQL 2008 and 2012 installed.  Then I added 2008R2 and deleted 2008.  After that when trying to open a database (from App_Data folder of Visual Studio project) using the Server Explorer in Visual Studio I received the following error message: "Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.".  To resolve I simply deleted the following folder and then restarted Visual Studio: C:\Users\...\AppData\Local\Microsoft\Microsoft SQL Server Data

Tags:

SQL Server | Visual Studio

nuget.psm1 Cannot be Loaded Because the Execution of Scripts is Disabled on this System

by 29. November 2013 08:43

File C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft Corporation\NuGet Package Manager\2.7.40911.225\Modules\NuGet\nuget.psm1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

Launch Powershell as admin and run this command: "Set-ExecutionPolicy RemoteSigned"

Restart Visual Studio

Tags:

Visual Studio

SharePoint Document Sets

by 27. November 2013 08:49

Tags:

Sharepoint

SharePoint Always Run Configuration Wizard on All Farm Servers After Server Patching

by 26. November 2013 13:52

After patching (SharePoint updates) you need to run the configuration wizard.  The configuration wizard has to be ran on all SP servers in the farm. There is a command line that forces the wizard to re-run in the event of an issue or failure with the wizard. 

Psconfig.exe -cmd upgrade -inplace b2b -wait -force.

Tags:

Sharepoint

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