Friday, January 23, 2015

Monday, December 29, 2014

Consuming a REST service

            string jsonRequest = "REST URL";
            CredentialCache credCache = new CredentialCache();
            credCache.Add(new Uri(jsonRequest), "NTLM", CredentialCache.DefaultNetworkCredentials);
            HttpWebRequest spRequest = (HttpWebRequest)HttpWebRequest.Create(jsonRequest);
            spRequest.Credentials = credCache;
            spRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";
            spRequest.Method = "GET";
            spRequest.Accept = "application/json;odata=verbose";
            HttpWebResponse endpointResponse = (HttpWebResponse)spRequest.GetResponse();

            if (endpointResponse.StatusCode == HttpStatusCode.OK)
            {
                using (endpointResponse)
                {
                    using (var reader = new StreamReader(endpointResponse.GetResponseStream()))
                    {
                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        try
                        {
                            string jSON = reader.ReadToEnd();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
            }

Tuesday, August 5, 2014

Grouping datatable column using LINQ in C#

 Grouping datatable column using LINQ in C#


var grouped = from table in dt.AsEnumerable()
                          group table by new { placeCol = table["Place"] } into groupby
                          select new
                          {
                              Value = groupby.Key,
                              ColumnValues = groupby
                          };

            foreach (var key in grouped)
            {               
                Console.WriteLine(key.Value.placeCol);
                Console.WriteLine("---------------------------");
                foreach (var columnValue in key.ColumnValues)
                {
                    Console.WriteLine(columnValue["Name"].ToString());                   
                }
                Console.WriteLine();
            }
            Console.ReadLine();

For additional info:

Saturday, December 1, 2012

How to add a dll to GAC in Windows 7


How to add a dll to GAC in Windows 7

Today I started developing SharePoint application in Win 7 and faced some peculiar issue - I was not able to drag and drop my applications assembly into the gac. So, here comes the main points that you need to keep in mind to deploy one assembly in Win 7 GAC:

1. You must be a member of the Administrator Group.

2. Navigate to "C:\Windows\assembly" in the explorer and right click on it and select "Open in new window".

3. Type 'cmd' in run and as it appears in the top, right click on it and select "Run as administrator".

4. In the command prompt navigate to "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64"

5. Now use the following command: gacutil -i "full path of the file system\XYZ.dll"

6. You will get a message "Assembly successfully added to the cache"

7. Refresh the assembly folder that you have opened in step 2 and you will find your applications assembly there.

http://www.thespgeek.com/2010/11/how-to-add-dll-to-gac-in-windows-7.html

Wednesday, August 8, 2012

Overflow hidden on table - displaying without scroll bar

<table style="width:50%;table-layout:fixed;">
<tr>
<td style="overflow:hidden;white-space:nowrap;">The Writing Life: The point of the long and winding sentence The Writing Life: The point of the long and winding sentence</td>
</tr>
</table>

Remove all special characeter in String.


Remove all special characeter in String.
string title = "You, should be <careful. with , (your current approach) ";
title = Regex.Replace(title, "[^0-9a-zA-Z]+", " ");

Output:
You should be careful with your current approach

Regex.Replace(title, "[^0-9a-zA-Z]+", ""); -- also Remove Space.

Output:
Youshouldbecarefulwithyourcurrentapproach

Monday, July 30, 2012

IE text-decoration with images issues

<style type="text/css">
img{
border:0px;
}
img a, img a:link, img a:active, img a:visited, img a:hover{
border:0px;
}
</style>