Wednesday, 19 June 2013

Convert WSDL file to a C# class and then DLL


Today I was trying to update a web reference of custom web services in my project but because of some reason visual studio 2010 wasn't getting the latest methods I added even though I could see them using browser. Hence to get around problem I converted WSDL file into C# class and then into a dll.

You can target dll to any framework you would like. In order to get DLL in .Net 4.0 framework try following steps;

For getting you library dll in.Net 4.0 framework you will require Visual Studio 2010 tools installed on your machine, however for it in .Net 3.5 framework you will need Visual Studio 2008.


  1. Open Visual Studio Command prompt as a administrator by going to Start menu > All Programs > Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio Command Prompt (2010).
  2. Put your WSDL file in somewhere accessible e.g. in this case I will put it in my C drive and getting output CS class in C drive too but you can change it. Type this command and press okay,

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>wsdl /l:C# /out:C:\OutPutClassName.cs C:\myWebService.wsdl
  3. Above command will generate a CS class in your C drive, now if you want to convert this class into dll in .Net 4.0, type this command;

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>csc /target:library /r:System.Data.dll /r:System.Data.Services.Client.dll /out:C:\OutPutClassName.dll C:\OutPutClassName.cs

    Above command will get you class library dll in .Net 4.0 framework.
  4. In order to get ..Net 3.5 use this command,

    C:\Program Files\Microsoft Visual Studio 9.0\VC>csc /target:library /r:System.Data.dll  /out:C:\OutPutClassName.dll C:\OutPutClassName.cs
MSDN Reference: http://msdn.microsoft.com/en-us/library/bb332338.aspx#msdnwcfhc_topic6

Wednesday, 5 June 2013

Right way of installing assembly into GAC in Windows Server 2012


In previous version's of Windows Server we were able to simply drag and drop assemblies into GAC folder which wasn't recommended at all, however being in a development environment (Windows Server 2012) when I tried to drag and drop a DLL into GAC, I received this error,




Now if you want to install assembly to GAC following steps,

  1. Assuming you are new to Windows Server 2012, Move your mouse pointer to right bottom of your screen just next to Date & Time.
  2. Click on "Search" tile.
  3. Now enter "cmd" in search text box.
  4. Most likely you will see two apps named as "Command Prompt" and "Visual Studio Command Promp...".
  5. If you will right click on "Visual Studio Command Promp.." it will give you few options at bottom of screen as show in picture below,






  6. Click on "Run as administrator" and press "Yes" for typical dialogue appears each time you try to start       a processes as administrator as security confirmation.
  7. Now type down this command,

    cd C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC
  8. Copy your assembly to folder directory,

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC
  9. Once assembly is copied you can use following syntax to install assembly to GAC,

    gacutil /i mySolution.myProject.dll
    an IIS reset will be produced as a result of above command so be careful as if you might break any on going process

That's it. Your assembly is installed, you can follow the procedure as many times as you want.

For more information please check this MSDN link out: http://msdn.microsoft.com/en-us/library/ex0ss12c(v=vs.80).aspx

Tuesday, 28 May 2013

SQL Sever 2008 R2 has an unsupported version error in SharePoint product configuration wizard


I was trying to create a SharePoint 2013 development VM and came across this nasty error,

SQL server at "SQLSERVERNAME" has an unsupported version at "xxx.xxx.x.x" (IP address). Please refer to http://technet.microsoft.com/library/cc262485(office.15)?ocid=fwlink#section5 for more information on the minimum required SQL Server Versions and how to download them.






I also tried PowerShell to create a configuration database but got same error,



PS C:\Users\Administrator> New-SpConfigurationDatabase
cmdlet New-SPConfigurationDatabase at command pipeline position 1
Supply values for the following parameters:
DatabaseName: SharePoint_Config
DatabaseServer: MSSQLSERVER
FarmCredentials
Passphrase: myPass



I fixed the error by installing update for SQL Server by Microsoft to make it work with SharePoint 2013. I downloaded Microsoft® SQL Server® 2008 R2 Service Pack 1 from http://www.microsoft.com/en-us/download/details.aspx?id=26727

Running this setup will update your SQL Server R2 to SP1 which is requirement for SharePoint 2013.



Upgrading your MCITP : SharePoint Administrator 2010 to SharePoint 2013 Solution Expert


If you already earned MCITP : SharePoint 2010 Administrator certification then you can easily upgrade it to SharePoint 2013 Solution Expert by passing 417, 331 and 332 exams, as shown in picture below,



Source : http://www.microsoft.com/learning/en/us/mcse-sharepoint-certification.aspx#fbid=MDgfOwqPuct?upgradeable

There isn't any upgrade path came out yet(28-05-2013) for MCPD : SharePoint 2010 Professional developers to upgrade and get certified in SharePoint 2013.

Thursday, 23 May 2013

Capturing iPad or iPhone traffic using Fiddler2

Recently I have been given a task to find out why iPad application isn't getting the "correct" data from our SharePoint environment. I don't know much about how iPad has been developed but I been told it's consuming custom web services. Hence I downloaded Fiddler2 to analyse iPad traffic and see what has been requested by iPad and what is it getting in return.

Once you downloaded Fiddler2 on your computer, you can add proxy details to your iPad as shown in picture below,




Enter IP address of your computer in front of Server Make sure your port number matches one on Fiddler2 by default it's "8888". You can change default port by going to Tools > Fiddler Options > Connections > Fiddler listens on port:  as shown in picture below,




Now if you also want to capture HTTPS (secured) traffic then check boxes as shown in picture below,




Next step would be clicking on "Export Root Certificate to Desktop" and sending certificate you just exported on desktop to your iPad through email. Once you received it on your iPad just try opening the certificate and install it.

That's it, you can start capturing traffic now, one thing I would like to mention is that my iPad and Computer has been connected to same intranet network while I was debugging.


Tuesday, 21 May 2013

Restricting picture size in ItemAdding event receiver for SharePoint picture library


If you want to restrict user from uploading a picture larger then specified size (width x height) then you can use code below.

Please note it only works when user uploads a single picture file, when user uploads multiple files, SharePoint opens Microsoft picture manager to upload several pictures hence HTTP Context comes as null. I tried to find a fix for it but I couldn't so if someone reading this post please comment the solution. Until then you can disable multiple picture uploads to library.

Ways around would be create a custom list definition and then a custom upload form with all of code logic behind, you can make it work for single files or several files but depends on your code behind logic and requirements.



class PicLibraryImageSize : SPItemEventReceiver
    {
        HttpContext _current;
        public PicLibraryImageSize()
        {
            _current = HttpContext.Current;
        }

        public override void ItemAdding(SPItemEventProperties properties)
        {
            try
            {
                this.DisableEventFiring();

                if (IspicTooLarge())
                {
                    properties.Cancel = true;
                    properties.ErrorMessage = "Picture Too large to upload !";
                }
            }
            catch (Exception ex)
            {
                //Log it
            }
            finally
            {
                this.EnableEventFiring();
            }
        }

        private bool IspicTooLarge()
        {
            HttpFileCollection cFiles = _current.Request.Files;

            HttpPostedFile pFile = cFiles[0];

            using (System.Drawing.Image image = System.Drawing.Image.FromStream(pFile.InputStream))
            {
                if (image.Width > 800 ||  image.Height > 600)
                {
                    return true;
                }
                else
                    return false;
            }
        }
    }

Wednesday, 24 April 2013

Copying GAC before deployment on SharePoint Production WFEs servers


Few days back I needed to deploy few projects on production server's, since our SharePoint 2007 is properly customized and GAC is packed with custom solutions assemblies, and these solutions do get updated regularly. These DLLs depends on each other so if I update GAC with wrong version of a custom DLL it will break customized SharePoint which I don't want to happen therefore need a backup of GAC as part of backup plan.

Of course we have SharePoint Team foundation and we document each change, but when your farm is broken because of your newly deployed project solutions (which also updated few customized DLLs) you want to roll back quickly and without taking any risk of "wrong documentation" or if someone updated production server and forgot to update TFS somehow.

Copying DLLs out of GAC isn't really a difficult task and is really helpful when it comes to roll back. Follow these steps to backup everything in GAC folder or only the DLLs you think you need,


  • Click on Start and then on Run.
  • Put this command in text box and click "OK", as shown in figure below.
                %windir%\assembly\GAC_MSIL





  • A window will appear with several folders but only folders you might need are ones shown in picture below,


  • Now you can copy all folders for backup or just find particular DLLs you need using search box. 
I personally copy all of folders and then once everything get's deployed perfectly, I delete the backup.