Sandip's Programming Zen

An attempt to share tech/coding experiences

Archive for March 2010

Convert scanned pdf into image in C#

leave a comment »

I needed to convert scanned pdf into any image format so that I can run OCR operation for one of the DMS solutions I am working on. Actually I am using Tesseract (Open source OCR solution from Google) for OCR and it only takes image format as input. After spending few hours searching and trying few solution I zeroed in on this codeproject article which is making use of Ghostscript to achieve the core functionality.
So far this is the only solution I think works seamlessly on most windows platforms including Win7 (already tested on XP, Win2003, Win7).

Written by Sandip

March 23, 2010 at 7:16 am

Posted in .Net

Tagged with , , ,

C#: Accessing resources on network

leave a comment »

Accessing files and other resources on network from within code is achieved in following way in C# (of course there are other ways but this seems neat):

Take following assembly reference first:

using System.Runtime.InteropServices;

[DllImport(“advapi32.dll”, SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

Private void YourFunction()


WindowsImpersonationContext wic;
IntPtr tokenHandle = new IntPtr(0);
bool returnValue = LogonUser(f.cUserName, f.cDomain, f.cPassword, 2, 0, ref tokenHandle);
WindowsIdentity ImpersonatedIdentity = new WindowsIdentity(tokenHandle);
WindowsImpersonationContext MyImpersonation = ImpersonatedIdentity.Impersonate();

wic = MyImpersonation;

// do some file IO activity here on server…



Written by Sandip

March 15, 2010 at 1:16 pm

Posted in .Net, Programming

Tagged with , ,

C# MP3 files organizer

leave a comment »

I have a huge collection of mp3 music files and locating music was bit difficult if I would like to hear a particular artist, I quickly tried to search on google , found some programs but unnecessarily complex, so I wrote my own , which is very simple.  it does following:

  • Asks for a target directory where your mp3 files are located.
  • On click of a button it extracts the meta info and organizes the files in folders per artist.

It’s very basic but useful to me at least. you are free to modify/use/distribute at your own risk 🙂

Download it from here.

Written by Sandip

March 15, 2010 at 1:07 pm

Posted in .Net, Programming

Tagged with ,