Friday, February 20, 2015

Print a selected area on a page

On the style tag add the below contents

style type="text/css" media="print"
.no-print { display: none; }

The contents which do not have to be printed can be given under a div tag with the class name "no=print"


Friday, February 13, 2015

Upload multiple files using jQuery plugin


  • Refer the jquery.MultiFile.js
  • Add a ASP.Net file upload control to the page
  • Add the following code on the button click event for uploading the files

HttpFileCollection fileCollection = Request.Files;
for (int i = 0; i < fileCollection.Count; i++)
{
    HttpPostedFile uploadfile = fileCollection[i];
    string fileName = Path.GetFileName(uploadfile.FileName);
    if (uploadfile.ContentLength > 0)
    {
        uploadfile.SaveAs(Server.MapPath("~/UploadedFiles/") + fileName);
        lblMessage.Text += fileName + "Saved!!!";
    }
}

The multiple file upload plugin can be downloaded from here

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>