please leave a comment so that i know what not to write about


Friday, December 31, 2010

Data manipulation in azure development storage by using web services – workaround

While developing the Azure project this was the biggest problem I came across and being just a newcomer in this area I could not solve it. So I figured a way around that worked perfectly well and then I used it to finally make a working project. Nearly all the solutions I came across in the different portals were about the same problem without the development storage anywhere in question but for the people who first need to make a working solution in the development storage using anything like the VS2010 there was no help nowhere.
The problem was that while accessing data which was stored in a blob in cloud storage through a web service by a Silverlight client. It gives an impression to the storage of the cloud that this is being done by cross site scripting (this is what I got from all the different sources I read) and because this was not allowed the cloud project (webrole in my case) was blocking the request and was returning nothing in return.
So this solution that I figured out is to manually send request on the endpoint exposed by the web service and then retrieve a JSON object as the data.
If you have the similar problem you can use this to
Below is the section of the code in question fully explained. J

private string RootUri
                string scheme = HtmlPage.Document.DocumentUri.Scheme;
                string host = HtmlPage.Document.DocumentUri.Host;
                int port = HtmlPage.Document.DocumentUri.Port;

                string template = "{0}://{1}";
                string uri = string.Format(template, scheme, host);
                if (port != 80 && port != 443)
                    uri += ":" + port;
                return uri + "/";
This piece of code constructs a uri so that every time some data needs to be retrieved this can be used.

void MainPage_Loaded(object sender, RoutedEventArgs e)
            Uri getMspListUri = new Uri(RootUri + "Service1.svc/GetMspList");
            WebClient getMspListClient = new WebClient();
            getMspListClient.OpenReadCompleted += new OpenReadCompletedEventHandler(getMspListClient_OpenReadCompleted);

This piece of code here is the code inside the MainPage_loaded event and this code is first creating a Uri object using the root Uri and the endpoint of the webservice. With the function name to be called is the GetMspList (this thing is later explained in this post). After this a Webclient object is made and in its OpenReadCompleted event handler I have given the name of the function to be called. That being getMspListClient_OpenReadCompleted

After this Webclient object is asked to read the data. The first time I was doing it I was praying for it to work because I had put so much in this problem already.

void getMspListClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
            Stream stm = e.Result;
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<Dictionary<string, string>>));
            //this object here serializes deserializes the objects that the webservice is sending

            List<Dictionary<string, string>> mspList = (List<Dictionary<string, string>>)ser.ReadObject(stm);
            //this is the peice of data i was receiving

            foreach (var msp in mspList)
                MspPushpin pin = new MspPushpin();
                if (msp["Lat"] != "" && msp["Lon"] != "")
                    Location d = new Location(Convert.ToDouble(msp["Lat"]), Convert.ToDouble(msp["Lon"]));
                    pin.Location = d;
                    pin.Name = msp["FirstName"] + msp["LastName"];
                    pin.UserId = msp["UserId"];
                    pin.EmailAddress = msp["emailAddress"];
                    pin.ImageUri = msp["ImageBlobUri"];

                    ScaleTransform st = new ScaleTransform();
                    st.ScaleX = 0.25;
                    st.ScaleY = 0.25;
                    st.CenterX = (pin as FrameworkElement).Height / 2;
                    st.CenterY = (pin as FrameworkElement).Height / 2;

                    pin.RenderTransform = st;
                    pin.MouseEnter += new MouseEventHandler(pin_MouseEnter);
                    pin.MouseLeave += new MouseEventHandler(pin_MouseLeave);
                    if (d.Latitude == 0 && d.Longitude == 0)
                    { }
                        PushPinLayer.AddChild(pin, d);
            status = "MSP list retrived sucessfully";

The code is explained using the comments within the code.

Now the turn of the code of the webservice sending the data.

        [WebGet(UriTemplate = "GetMspList", ResponseFormat = WebMessageFormat.Json)]
        public List<Dictionary<string, string>> GetMspList()
            List<Dictionary<string, string>> mspList = new List<Dictionary<string, string>>();
                CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
                mspDataServiceContext context = new mspDataServiceContext(account.TableEndpoint.ToString(), account.Credentials);

                foreach (msp _currentMsp in context.msps)
                    Dictionary<string, string> mspDetails = new Dictionary<string, string>();
                    mspDetails.Add("ImageBlobUri", _currentMsp.ImageBlobUri);
                    mspDetails.Add("emailAddress", _currentMsp.EmailAddress);
                    mspDetails.Add("Lon", _currentMsp.lon.ToString());
                    mspDetails.Add("UserId", _currentMsp.UserId);

            catch (DataServiceRequestException ex)
                throw ex;

            return mspList;

And this I think is self-explanatory and is just an example of normal code writing In a webservice in c#. if there is some problem in the entire post please mail me or just put a comment :)

following is a link to the complete project


Tuesday, December 28, 2010

ParameterLess construct

When I was creating my first cloud app that’s used Microsoft Azure for storage and computation purposes I came across a strange problem which wasn’t related to the Azure itself but was more related to the c# and the .net framework.
When I was writing the code I made a Class which had no parameter less construct. Objects of this class were then used in the program. Because this class was derived from Ienumerator I could actually user Foreach() on the objects of this class but to my surprise the code shown below was showing error at the highlighted line.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;
namespace WebRole1
public class mspDataServiceContext : TableServiceContext
public mspDataServiceContext(string baseAddress, StorageCredentials credentials)
: base(baseAddress, credentials)
static int c;
public IQueryable<msp> msps
return this.CreateQuery<msp>("msps");
static int Count()
return c;
public int AddMsp(msp m)
foreach (msp k in this.msps)
if (k.UserId == m.UserId)
return 0;
//for (int i = 0; i <mspDataServiceContext.Count(); i++)
// if (m.UserId == msps.ElementAt(i).UserId)
// return 0;
this.AddObject("msps", m);
return 1;//indicatiing successful addition
public int DeleteMsp(string UserId)
foreach (msp k in msps)
if (k.UserId == UserId)
return 1;//indicating sucessful deletion
return 0;//indicating missing entry
public int updateMspLocation(string UserId, double lat, double lon)
msp m = null;
foreach (msp k in msps)
if (k.UserId == UserId)
m = k;
else return 0;
} = lat;
m.lon = lon;
return 1;//indicating successful updation
public void DeleteAll()
foreach (msp m in this.msps)
The error was later rectified by adding a parameter less construct in the class because the foreach() command was making a msp k in every step and there was no parameterless construct so the compiler wasn’t allowing it to be made.
link to the full project is given below

Friday, September 17, 2010

have you forgotten the password to your windows administrator account?

If the answer is yes then go ahead and read the entire post.
There are two full proof ways depending upon what your installation contains
1) You have another administrator account that you can log into
2) You don’t have another administrator account that you can log into
If you have another administrator account that you can log into things will be a little simple
We will make use of the net user command and there will be no need of installing any third party software in this case. You just need to follow the procedure given and in less than 2 minutes you will be able to reset the password. This same trick will work for any windows installation let it be XP or Vista or Window 7.
1) Log into the administrator account u can log into
2) In the start menu type cmd
3) Now right click on the cmd.exe and click on Run as administrator option.
4) UAC (user accounts control) build in your operating system will ask for permission so say yes and allow the cmd.exe to run.
5) Now you will have a black screen in front of you which is the command prompt.
6) Type net user in the cmd prompt and press enter
7) You will see a screen like the one above will names of all the users in your system
8) Now type net user [username] [password]
Here the [username] should be replaced with the username of the account of which you want to change the password and [password] should be replaced with the new password you want to keep.
Ex. net user parv0888 password
Here parv0888 is my accounts username and password is the new password I want to keep.
9) If everything goes off well you will get a message that the command has completed successfully. You are done
1) Logoff your current account and log in the administrator account which made you read this post with the new password.
If you don’t have another administrator account
In this case you will have to use a Microsoft tool named Locksmith which is a part of the Desktop Optimization tool kit. Though there are other third party tools available to this job whose list you can get here. I have tried and tested nearly all of them and Locksmith is the best and the easiest. The problem with Locksmith is that it is not a free tool you can download it via MSDN L.
Once you have the Desktop Optimization Pack follow the procedure.
1) The Microsoft Desktop Optimization Pack (MDOP) is an .iso file. So to run it you will have to either burn it on a DVD (for this software’s like Nero and Roxio can be used) or simply attach it on a virtual drive( to attach it on a virtual drive you can use Magic Disk software).
2) When you will run it a blue screen will appear with many options. Though it will be fun to explore all of them and I can assure all of them are damm interesting and useful. For now we will concentrate on Diagnostic and recovery toolset (DaRT). So click on the option
3) You will encounter a no of options again asking you to choose the type of DaRT to install. Depending upon your window 7 architecture x86 or x64 choose the installation type.
4) These are the messages will declare the installation completion.
7 6
5) Now run the ERD commander boot media wizard. This will be present in your start menu now and this is the thing that we have just installed. Click next and it will ask for the window 7 DVD drive.
6) Insert your window 7 DVD in your DVD drive and click browse button and select your DVD drive and then click next. After this the process will take some time as the ERD commander will take some time to extract the files out of your Window 7 DVD.
7) Once all the files have been extracted. The process becomes easy and now you just need to save the .iso file that the ERD commander wants you to save. This is the .iso file that you will be using to finally reset your password.
8) Once the .iso file have been saved burn it on a DVD drive. This iso file cannot be simply copied to a usb drive and used. You can use software’s like Nero or Roxio to do this thing.
9) After the burning process completes put the DVD in the system whose password needs to be reset and turn on the system. Depending on the system there can be a no of ways to change the default boot sequence. One that works on most of the systems is to keep pressing Delete key again and again from the time you see the first thing on the monitor till you see the BIOS setup will be something like this one.
10) Get to the boot section and change the boot sequence. Make the first boot device your DVD drive. Press the appropriate key that will save the changes made will restart the system. In my case that is F10.
11) When the system restarts. It will boot from the optical media. First it will load all the files and then the program will load itself. It will ask you if you would like to initialize the network connectivity. Press NO. then again press no one the next question and NEXT on the third one. It will take some time to detect the windows already installed in your system. In case of multiboot systems just select the installation that contains the user whose password needs to be reset. And click next.
12) On the next screen shown select following option
13) On the screen after that select
14) Now simply select your username and enter the new password.
Click next and you are good to go
15) restart the system and again change the boot sequence. For the first time when you will log into the administrator account it will ask you to change the password. Do it
Congrats you password has now been removed J

Friday, August 13, 2010

Protecting Private Data

Mostly to protect important data or sometimes private pics we use encrypting programs like the AXcrypt. Which do not allow viewing individual files in the chunk of files encrypted together. This makes viewing files a tough process especially when the size of the files runs into several GBs. I have seen programs like these taking hours together to decrypt files on a dual core machine like mine. Maybe they are not made to take advantage of both of the processors. Also when all the files are decrypted there is a greater chance for the security to be compromise
While I was thinking about this problem. I found out a solution that can be implemented by using only the tools that come with the Window 7. The tools are
1. Ability to attach virtual hard disk
2. Bitlocker
Many of you might have got what I am up to for others let’s see HOW TO PROTECT DATA.
The process comprises of making a new .VHD file
  1. Attaching it
  2. Encrypting it
  3. Then adding the data
  4. Finally detaching it
And your data is protected and now you can also see individual files without decrypting them.
  • · Open the start menu
  • · Type compmgmt.msc
  • · Double click on the storage option
  • · Double click on the disk management
  • · Go to the actions pane
  • · Click on more actions
  • · Finally click on create VHD
  • · Enter the location and decide a file name
  • · Then click on the dynamic expanding option
  • · Enter the amount you would need to store the data
  • · Now the disk is made but still the area will appear to be unallocated and will appear in black
  • · Right click on the disk and then make a new simple volume
  • · Make it a separate drive
  • · In the end it will ask for the drive letter you want to assign to the drive. Choose any one you like
  • · Now after attaching the drive. The drive will be present in the ‘my computer’ on the drive letter that was chosen by you.
  • · Open MyComputer
  • · Right click on the drive just added
  • · And then select TURN ON BITLOCKER
  • · Then it will ask for a password. Specify a nice and strong password one which is hard for anybody to guess and at the same time that is easy for you to understand
  • · On clicking next your drive will start encrypting
  • · In the end the BITLOCKER will ask you to save a file. This is the file which you can use in case you forget the password. Save it in a safe place and it is not recommended that you should keep the file in the same system as that of the drive and data. I keep my file on SkyDrive (
Congrats now your drive is encrypted.
The default icon of the drive will change to something which a lock.
Adding data to the encrypted is same as adding data to a normal drive just copy and paste.
Finally when you are done. Now you will need to detach the drive. Though you can keep the drive attached it will surely attract anyone who wants to access your private data. So a good practice is to detach it and then reattach it whenever needed.
  • · To detach the drive just safely remove it. Click on the icon on the tray that says SAFELY REMOVE HARDWARE AND EJECT MEDIA. And then remove MSFT VIRTUAL DISK SCSI DISK DEVICE. You are done. And now your data is safe and also portable. You can just copy the .VHD file and take it anywhere you go in your portable drive and then attach it whenever needed.
if you get stuck somewhere
mail me @

Tuesday, July 20, 2010

Performance Monitor(perfmon.exe) must for window developers

Recently I attended Microsoft Community Tech Days at New Delhi. The last session of the event was taken by Bijoy who is presently working with Microsoft. The session was about .NET tips and tricks. The session was extremely informative and really forced all the developers that were present in that auditorium to actually think about the process we take for measuring the resources and also the process we use for debugging an application. He laid stress on many tools one of which was performance monitor (Perfmon).
Perfmon is supplied by the Microsoft with the operating system and there is no need for us to install anything to use it. It can actually capture live data about the performance of our system. A newly installed software or monitor the changes that take place in the registry during a particular time period.
A lot of detailed information is present at TechNet. But there were no videos for the starters so here is one giving Detailed description about how to get started.
part1 -

part2 -

If you get stuck up somewhere mail me @

Tuesday, July 13, 2010

MSP selections are ON - India

For those who don't know what MSP stands for MSP stands for Microsoft Student Partner. This student partner program is run by Microsoft to choose among many a few who are enthusiastic about technology and Microsoft. students from all over the globe are selected for this program. students who are selected are equipped with the task of informing others about the Microsoft technologies and products like the VS 2010:) and Silverlight etc etc. for this they may conduct sessions or hands on labs. in return MSPs get a lot. the best thing being the MSDN premium account :)
The good news is that now you can apply to be an MSP. All you need to do is go to the student-partners web site and click on the apply now box.
Though the selection process changes every time. The process will test your technological and public speaking skills and a technology related blog is always preferred. last time they asked us to upload a 3 min video about any MS technology. and then after that they asked us to collect 150 points by conducting various activities. last date to apply is 15th aug 2010.
details about creating student tech clubs is available here

mail me if you get stuck some where

Monday, July 5, 2010

bootable USB drive

What makes a USB drive bootable?

When I was searching for the process of making my pendrive bootable. I came across many processes and software’s that could do it but none of the sources told me what is the science behind this. Why my pen drive is bootable after the process and was not before. So I decided to write an article of my own for this.
This is also my first post. So please do comment what you dislike and also like about the post and also if you need any help.
The process of making a pendrive bootable and to use it with window 7 and other window operating systems the process that was described by the sources was
1. Open command prompt(cmd) with administrator privileges
4. Then assuming your USB disk is DISK1. Type SELECT DISK 1
5. Type CLEAN
8. Type ACTIVE
10. Type ASSIGN
11. Type EXIT
12. Insert window installation disk
13. In the command prompt window type D: CD BOOT(assuming your cd/dvd drive is labelled D)
14. Type BOOTSECT.EXE /NT60 H: (assuming your USB drive is labelled H)
15. Copy all the contents of the windows installation disk into the USB drive
Let’s start with

DISKPART enables a superset of the actions that are supported by the Disk Management snap-in. The Disk Management snap-in prohibits you from inadvertently performing actions that may result in data loss. It is recommended that you use the DISKPART utility cautiously because DISKPART enables explicit control of partitions and volumes.
DISKPART can perform various functions like
1. converting a basic disk to dynamic disk
2. converting a dynamic disk to basic disk
3. DISKPART can create a partition at an explicit disk offset
4. DISKPART can be used to delete missing dynamic disks
DISKPART commands operate on a specific target disk, partition, or volume. The targeted object has "focus." Focus simplifies the common configuration task in which you create multiple partitions on the same disk. An object is put into focus by the select command. All Commands except for list, help, rem, exit, or help require focus.

LIST DISK is a command in the bigger DISKPART utility. LIST DISK is used to retrieve a summary of information about each disk in the computer. Only fixed disks (for example, integrated device electronics [IDE] or small computer system interface [SCSI]) or removable disk (for example, 1394 or USB) are listed. The removable drives are not displayed. The disk with the * asterisk has current focus.

Select disk command is used to select a particular disk out of the list that was presented by the LIST DISK command.

CLEAN command is used to delete all the partitions from the current in focus disk. Now because the partition information in the most used partition resides in the first sector of the disk clean command deletes that information by zeroing it and thereby deletes all the partition information from the drive.
CLEAN ALL command zeroes all the sectors on the drive in focus thereby deleting all the data.

This command creates a primary partition in the disk in focus.
A primary partition contains one file system. In MS-DOS and earlier versions of Microsoft Windows systems, the first partition (C:) must be a primary partition. Some operating systems are not limited in this way; however, this can depend on other factors, such as a PC's BIOS.
The partition type code for a primary partition can either correspond to a file system contained within (e.g. 0x07 means either an NTFS or an OS/2 HPFS file system) or indicate the partition has a special use (e.g. code 0x82 usually indicates a Linux swap partition). The FAT16 and FAT32 file systems have made use of quite a number of partition type codes over time due to the limits of various DOS and Windows OS versions. Though a Linux operating system may recognize a number of different file systems (ext2, ext3, ReiserFS, etc.), they have all consistently used the same partition type code: 0x83 (Linux native file system).

This command selects the first partition from the drive in focus. Because earlier we deleted all the partition and then we made a brand new partition on the drive this partition will be the one that we created recently.

This command tell the firmware that this particular partition of the drive is ‘active’ or bootable

As the name suggests this command formats the drive in focus and deletes all the data in the drive plus changes the file system to NTFS. This is needed to make the drive bootable. NTFS as it is has many advantages over fat formats like quota and security.

This command is used to assign a drive letter or the mount point to the partition in focus. If no drive letter is mentioned as in our case the next free drive letter is assigned to the partition.

This obviously exits the Diskpart utility.

Bootsect.exe updates the master boot code for hard disk partitions to switch between BOOTMGR and NTLDR. You can use this tool to restore the boot sector on your computer. This tool replaces FixFAT and FixNTFS.
Bootmgr is used in window vista and window 7 only and NTLDR was used in window xp and earlier versions to load the operating system while booting.
Bootsect can also solve your problem of dual boot when 2 operating systems are used one that uses NTLDR and other that uses BOOTMGR.
There was an error in this gadget