Wednesday 22 March 2017

Convert list into data table

   Here is the code to convert list into data table

   public DataTable ConvertToDataTable<T>(IList<T> data)
        {
            PropertyDescriptorCollection properties =
                TypeDescriptor.GetProperties(typeof(T));

            DataTable table = new DataTable();

            foreach (PropertyDescriptor prop in properties)
                table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);

            foreach (T item in data)
            {
                DataRow row = table.NewRow();
                foreach (PropertyDescriptor prop in properties)
                    row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
                table.Rows.Add(row);
            }
            return table;
        }

ConvertToDataTable(NameList);

Monday 24 October 2016

How to start Exe file using process start c# in IIS

How to start Exe file using process start c# in IIS I have searched a lot and finally I find solution.So I am writing here my be it will helpful to some one.
Problem : I have created a project with process start in c# it's running in local visual studio build,when I hosting it in IIS it's not running but it's starting the processes and nothing is displaying I checked it in task manager.Code sample:
Process process = new Process();
process.StartInfo.FileName = "calc.exe";
process.StartInfo.UseShellExecute = false;
process.Start();
process.WaitForExit();
And I have tried following solutions
nothing helped,Finally I Find solution my self.
Solution :

Asp.net with IIS runs as a service application, which means that it runs under another Window Station and Desktop. However, in Windows, the default visible Window Station and Desktop is WinSta0\Default, which is where the Shell(explorer.exe) runs. So the .exe you created is displayed in an invisible desktop.

Actually, Window Station and Desktop is a good sandbox for GUI security, since Windows do not want the normal GUI application to communication other Services applications through Windows Message.

To display the GUI from a non-visible service application, you have to break the security sandbox of WinSta0\Default, which is a little complex.

However, if you want to create a visible process, it is really hard. Normally, the recommended solution is creating a second GUI application like Winform, and the Asp.net and Winform can communicates through .Net Remoting or other Inter process communication technologies. When the Asp.net wanted to create the visible notepad process, it can tell the Winform client through Net Remoting, then Winform will simply Proces.Start notepad.exe on behalf of Asp.net process.

.Net Remoting :
    .Net Remoting is the solution to solve this problem(refer this link .NET Remoting with an easy example ) I am attaching the sample application to run calculator from IIS Server Click To Download


Have any queries comment here :)

Thanks,
Abinash

Tuesday 14 June 2016

Converting Asp ObjectDataSource into List

It's very easy to convert the  ObjectDataSource into a List, The ObjectDataSource don't have datasource property instead of that we will use select property to get the datasource values.

Example C# code given Below.

List<DeploymentEntity> codes = (List<DeploymentEntity>)DeploymentsDS.Select;

Example VB code given Below.


  Dim codes As List(Of DeploymentEntity) = DirectCast(DeploymentsDS.Select, List(Of DeploymentEntity))

Monday 18 April 2016

Script Manager in ASP

ScriptManager control registers the script for the Microsoft AJAX Library with the page. This enables client script support features such as partial-page rendering and Web-service calls.
You must use a ScriptManager control on a page to enable the following features of ASP.NET AJAX:
1. Client-script functionality of the Microsoft AJAX Library, and any custom script that you want to send to the browser.
protected void Button1_Click(object sender, EventArgs e)
{
    Page.ClientScript.RegisterStartupScript(
        this.GetType(),"myscript","alert('hello world!');");
}
2. Partial-page rendering, which enables regions on the page to be independently refreshed without a postback. The ASP.NET AJAX UpdatePanel, UpdateProgress, and Timer controls require a ScriptManager control to support partial-page rendering.
3. JavaScript proxy classes for Web services, which enable you to use client script to access Web services by exposing Web services as strongly typed objects.
[WebMethod]
public int Add(int a, int b) { return a + b; }

function CallAdd()
{
    // method will return immediately
    // processing done asynchronously
    WebService.Add(0,6, OnMethodSucceeded, OnMethodFailed);
}
4. JavaScript classes to access ASP.NET authentication and profile application services.
Sys.Services.AuthenticationService.login
Sys.Services.AuthenticationService.logout

<script type="text/javascript">
    function MyMethod(username, password)
    {
        Sys.Services.AuthenticationService.login(username,
            password,false,null,null,null,null,"User Context"); 
    }
</script>

The controls that UpdatePanel and ScriptManager are used for the ASP.NET AJAX Enabled sites.
  • We use them, firstly, because in traditional webpages the entire page is loaded after a postback, the HTML sent to the browser is much larger than it needs to be.
  • Second, because the entire page is replaced, the browser has to dismiss the old one and then draw the new one. This causes the page to “flicker,” which results in an unattractive user experience. enter image description here
The ScriptManager control serves as the bridge between the client page and the server. As it is like a bridge, you've to use this control if any of the other AJAX controls needs to be added. It manages script resources (the JavaScript files used at the client), takes care of partial-page updates as shown earlier, and handles interaction with your web site for things like web services and the ASP.NET application services such as membership, roles, and profile. Whenever one of the controls within the UpdatePanel causes a postback to the server, only the content within that UpdatePanel is refreshed.
If you analyze the data that gets sent from the server to the browser (using a network analysis tool like Fiddler or Wireshark), you would see that only a limited amount of data gets sent to the client.
You usually place the ScriptManager control directly in a content page if you think you need Ajax capabilities on only a handful of pages.
If you’re going to use Ajax functionality in many of your ASPX pages, you can place the ScriptManager in the master page, so it’s available in all pages that are based on this master.
You can only have one ScriptManager per page (i.e. only one bridge, if there happens two bridges then the page request/response may get confused from where to go!? :D), so if you add one to a master page, you can’t add another one to a content page. In order to access a ScriptManager control that is defined in a master page from a content page, you can use the ScriptManagerProxy.

Tuesday 12 April 2016

Group By Vs Partition By

The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.

They're used in different places. group by modifies the entire query, like:
select customerId,Name,number count(*) as orderCount
from Orders
group by customerId,Name,number 

But partition by just works on a window function, like row_number:
select row_number() over (partition by customerId order by orderId)
    as rowNum, customerId,Name,number over (partition by customerId order by orderId)
from Orders where rowNum=1

group by normally reduces the number of rows returned by rolling them up and calculating averages or sums for each row. partition by does not affect the number of rows returned, but it changes how a window function's result is calculated.

In this first query the full column will get grouped  and it will return the grouped results but in second query only the selected column get grouped and returns all results so here the rowNum used to get the correct result as expected.

Have any queries comment here :)

Wednesday 6 April 2016

Google Calendar integration with Asp.net using iFrame

It's very easy to integrate Google Calendar to asp.net

      After a long research I have find the solution for Iframe problem with google Calender API.When you directly use the following code in ASP.Net

 <iframe src="http://www.google.com/calendar/"" width="2000" height="2000"></iframe>

      It will not render the Google page it shows empty page the reason for this is, that Google is sending an "X-Frame-Options: SAMEORIGIN" response header. This option prevents the browser from displaying iFrames that are not hosted on the same domain as the parent page.
See: Mozilla Developer Network - The X-Frame-Options response header google page will not allow you to render the website in IFrame they enabled X-Frame.

 Solution 

      Please follow the steps to create a iFrame inside the google calendar application
  • Go to the google calander then expand my calander from left tab.                                                                                                       
  • Then click on the calendar name and  go to the calendar settings page.                                                  
  • Then copy the iFrame link from embed this calander and use it in your Asp.Net application,here u can customize your google calendar by clicking Customize the color, size, and other.                                                                                                                                                                                                                                                                           
  • My sample project output :                                                                                                                                                                                                                                                    
How To Add,update,Delete Events in google calendar using ASP.Net Refer this link 

Have any queries comment here :)


Tuesday 5 April 2016

Auto Mouse Clicker

Click Here to download ->Auto Mouse Clicker


      Auto Mouse Clicker is a free Software for clicking mouse cursor according to user need. The Auto Mouse Clicker can be used to automate Left, Right Mouse Clicks, it even supports double mouse clicks for Right & Left Mouse Clicks.User can give how many times it need to click and same time he can set interval time also.Easy,simple and useful. Support Click where the mouse is.


 AutoMouseClicker

                       Click Here to download ->Auto Mouse Clicker


Any queries please comment below