Pages

Thursday, March 14, 2013

Web Application: Response.Redirect with POST instead of Get

You can use this aproach:
Response.Clear();
StringBuilder sb = new StringBuilder();
sb.Append("<html>");
sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>");
sb.AppendFormat("<form name='form' action='{0}' method='post'>",postbackUrl);
sb.AppendFormat("<input type='hidden' name='id' value='{0}'>", id);
// Other params go here
sb.Append("</form>");
sb.Append("</body>");
sb.Append("</html>");
Response.Write(sb.ToString());
Response.End();

As result right after client will get all html from server the event onload take place that triggers form submit and post all data to defined postbackUrl.

Continue Reading...  

Monday, March 11, 2013

SQL Loop through a table variable in SQL

Declare @Id int

While EXISTS(Select Count(*) From ATable Where Processed = 0)
Begin
    Select Top 1 @Id = Id From ATable Where Processed = 0

    --Do some processing here

    Update ATable Set Processed = 1 Where Id = @Id 

End
Another alternative is to use a temporary table:
Select *
Into   #Temp
From   ATable

Declare @Id int

While EXISTS(Select Count(*) From #Temp)
Begin

    Select Top 1 @Id = Id From #Temp

    --Do some processing here

    Delete #Temp Where Id = @Id

End
 
Continue Reading...   

SQL Store result in table variable

DECLARE @TempCustomer TABLE
(
   CustomerId uniqueidentifier,
   FirstName nvarchar(100),
   LastName nvarchar(100),
   Email nvarchar(100)
);
INSERT INTO 
    @TempCustomer 
SELECT 
    CustomerId, 
    FirstName, 
    LastName, 
    Email 
FROM 
    Customer
WHERE 
    CustomerId = @CustomerId
 
Continue Reading...  

Monday, February 4, 2013

Set Default Startup Profile for Firefox

To show select profile window on Firefox starup use -P -no-remote
e.g."C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -P -no-remote.

When you start Firefox as normal, It select profile which is selected last.
In normal start up to set default profile modify 
C:\Users\UserName\AppData\Roaming\Mozilla\Firefox\profiles.ini

Add Default=1 which profile need to set default
remove from other profile if found.

save file and make file as read-only.
Read-only file also not allow to create, rename, delete profile.

Thursday, January 24, 2013

C# Get My Public IP Address using ifconfig.me

using System;
using System.IO;
using System.Net;

private string createRequest(string url, string method)
{
    var request = (HttpWebRequest)WebRequest.Create(url);
    request.UserAgent = "curl";
    request.Method = method;

    using (WebResponse response = request.GetResponse())
    {
        using (var reader = new StreamReader(response.GetResponseStream()))
        {
            return (reader.ReadToEnd());
        }
    }
}

 string myIP = createRequest("http://ifconfig.me", "GET").Replace("\n", "");

C# Put Dispaly in Sleep Mode

[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);


//OFF
SendMessage(this.Handle, 0x0112, (IntPtr)0xF170, (IntPtr)2);

//ON
 SendMessage(this.Handle, 0x0112, (IntPtr)0xF170, (IntPtr)(-1));