Search This Blog

Thursday, December 16, 2010

WebRequest for sending SMS By GET METHOD

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Web.Security;
using System.Web.UI.HtmlControls;


public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SendSms();

}
protected void SendSms()
{
try
{

string userid1 = "test&";
string pass1 = "test&";
string appid1 = "test&";
string subappid1 = "test&";
string contenttype1 = "1&";
string selfid1 = "true&";
string from1 = "test&";
string to1 = "9911964567&";
string text1 = "thanks for visit our site&";
string dlrreq1 = "true&";
string alert1 = "1";
string url = "http://sms gateway url?";
string str_request = "userId=" + userid1 + "pass=" + pass1 + "appid=" + appid1 + "subappid=" + subappid1 + "contenttype=" + contenttype1 + "selfid=" + selfid1 + "from=" + from1 + "to=" + to1 + "text=" + text1 + "dlrreq=" + dlrreq1 + "alert=" + alert1;
WebRequest request = WebRequest.Create(url + str_request);
request.Method = "GET";
request.ContentLength=str_request.Length;
request.ContentType="application/x-www-form-urlencoded";
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
StreamReader sr = new StreamReader(stream);


}

}

HttpWebRequest for sms sending by post method

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Web.Security;
using System.Web.UI.HtmlControls;


public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SendSms();

}
protected void SendSms()
{
try
{

string userid1 = "test&";
string pass1 = "test&";
string appid1 = "test&";
string subappid1 = "test&";
string contenttype1 = "1&";
string selfid1 = "true&";
string from1 = "test&";
string to1 = "9994567831&";
string text1 = "thanks for visit our site&";
string dlrreq1 = "true&";
string alert1 = "1";
string url = "http://smsgateway api url?";
string str_request = "userId=" + userid1 + "pass=" + pass1 + "appid=" + appid1 + "subappid=" + subappid1 + "contenttype=" + contenttype1 + "selfid=" + selfid1 + "from=" + from1 + "to=" + to1 + "text=" + text1 + "dlrreq=" + dlrreq1 + "alert=" + alert1;
string from_sms = "";

StreamWriter sms_writer = null;
HttpWebRequest obj_request = (HttpWebRequest)WebRequest.Create(url + str_request);
obj_request.Method = "post";
obj_request.ContentLength = str_request.Length;
obj_request.ContentType = "application/x-www-form-urlencoded";
sms_writer = new StreamWriter(obj_request.GetRequestStream());
sms_writer.Write(str_request);
sms_writer.Close();
HttpWebResponse obj_response = (HttpWebResponse)obj_request.GetResponse();
using (StreamReader sr = new StreamReader(obj_response.GetResponseStream()))
{
from_sms = sr.ReadToEnd();
sr.Close();
}
}
catch (Exception ex)
{

string str = ex.Message;
lab_mesg.Text = str;
}
}
}

Friday, December 3, 2010

How can set identity in table column SQL2008 when data exist in table

Set identity in SQL2008 table column when data exist in table.
1.export data from local server to other server.
2.when select table from one server to other server.
3.Edit mapping option in window.
4.Click this button open window have option Edit SQL.
5.Click EDit SQLand change shema of table and then ok.
6.befor this select enable identity insert/Drop recreate option also.








Saturday, November 27, 2010

SQL Query

We have one table containing Questions and Ans. every questions have many ans .By this query you can fetch only one ques and related one ans.


Tuesday, November 16, 2010

Code Generate the Error log file

Hello all..
Here i am putting the code to generate the error in log file.I think it is much helpful for those who want to generate error in a folder which is not shown to the user.
Put the following Code in your project.

At Default.apsx Page



<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label1" runat="server" Text="FirstNumber"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label2" runat="server" Text="SecondNumber"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       
        <br />
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="submit"
            Width="135px" />
        <br />
   
    </div>
    </form>
</body>
</html>




 Default.cs Page



using System;

using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    int FirstNumber;
    int SecondNumber;
    int result;
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            FirstNumber = Convert.ToInt32(TextBox1.Text);
            SecondNumber = Convert.ToInt32(TextBox2.Text);
            result = FirstNumber / SecondNumber;
            Response.Write("result is:" + result.ToString());
        }
        catch (Exception ex)
        {

            throw;
        }
        finally
        {
       
        }
    }
}


Add new folder in your application and named it As MyError.in this folder the error is generate in a text file

Now Go into Solution Explorer and add new item as Global.asax page and put the following code in Application_Error Event.



Global.asax  page



//write the code at Application_error event
Exception err = (Exception)Server.GetLastError().InnerException;

        //Create a text file containing error details

        string strFileName = "Err_dt_" + DateTime.Now.Month + "_" +      DateTime.Now.Day
        + "_" + DateTime.Now.Year + "_Time_" + DateTime.Now.Hour + "_" +
        DateTime.Now.Minute + "_" + DateTime.Now.Second + "_"
        + DateTime.Now.Millisecond + ".txt";

        strFileName = Server.MapPath("~") + "\\MyError\\" + strFileName;

        FileStream fsOut = File.Create(strFileName);
        StreamWriter sw = new StreamWriter(fsOut);

        //Log the error details

        string errorText = "Error Message: " + err.Message + sw.NewLine;
        errorText = errorText + "Stack Trace: " + err.StackTrace + sw.NewLine;
        sw.WriteLine(errorText);
        sw.Flush();
        sw.Close();
        fsOut.Close();
        Response.Redirect("erroor.aspx")






Now add new .aspx page as error.axpx.we use this page to show some other error which is not acctual error.


error.aspx page



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="erroor.aspx.cs" Inherits="erroor" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    sorry !!!!!!!!!!
    You are attempting some wrong.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Back</asp:LinkButton>
   
   
    </div>
    </form>
</body>
</html>




Also we have to redirect the user to main page.So we take the error.cs page as


error.cs Page


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class erroor : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}




I think it is much useful for you.
Please comment if you have any Query,Suggestion or you like it.

Thanks






Wednesday, November 10, 2010

HTTP headers

Headers are name/value pairs that appears in both request and response messagges.The name of the heeader is separeted from the value
by a single colon.For Example..........................
this line in a request message...
User-Agent : Mozilla/4.0(compatiable;MSIE 6.0;Windows NT 5.1)
The purpose of this header is to supply the web server with information about the type of browser making the request.

http headerrs expose a great deal of information about your client as well as the server you are working,the application you are designing, as
well as the environmentt you are in....
the functionality for this is held in "Request.ServerVarriables",so you only need to access that.

Global.asax File

Global.asax file is a ASP.Net application file that is optional file.This file contains code for responding to
application-level events raised by ASP.Net based solution.The  global.asax file resides in the root directory
of asp.net based application.The Global.asax file is configured so that any direct HTTP request(via URL)is rejected automatically.so user can not download or view its contents.The asp.net framework recognizes automatically any changes that are made to global.asax file.The framework reboot all the application,flushes
all state information,closing browsers and restart the apllication domain.

The Global.asax file contain the following events:

1-Application-Init:-This event fired when an application initializes or is first called.It is invoked for all   httpApplication object instances.

2-Application_Disposed:  This event fired just before an application destroy.This is ideal location for cleaning
    previous used resourse.

3-Application_Error: This event fired when an unhandled exception is encountered within the appliction.

4-Application_Start-:This event fired when the first instance of the httpApplication class is created. it allows you to create  objects that are accessible by all the HttpAppplicaton instances.

5-Application_End:-This event fired when the last instances of HttpApplication class is destroyed.It
  is fired only once during the apllications lifetime.

6-Application_BeginRequest:Fired when application  request is received.It is the first events fired for a request.This is often a page request that a user enters.

7-Application_EndRequest:-The last events fired for an appllications request.

8-Session_Start: Fired when a new user visits the appllication web sites.

9-Session_End: Fired when a user's session times out,ends or they leave the application web sites.

10-Application_PreRequestHandlerExecute:-This event fired before the ASP.NET page framework begins executing an event handler like pages or web services.

11-Application_PostRequestHandlerExecutes:This events fired when the ASP.NET page framework is finished executing an event handler.

12-Application_PreSendRequestHeaders:This event fired before the ASP.NET page framework sends HTTP headers  to a requesting clients.

13-Application_PreSendContent: Fired before the ASP.NET page framework sends content to a requesting client(browser).

14-Application_AcquireRequestState: Fired when the ASP.NET page framework gets the current state(session state)  related to the current page request.

15-Application_RealeaseRequestState: Fired when the ASP.NET page framework completes execution of all events handlers.This result in all state modules to save their current state data.

16-Application_UpdateRequestCache: Fired when the ASP.NET page framework completes handler execution to allow caching modules to store responses to be used to handle subsequent request.

17-Application_AuthenticateRequest: Fired when the security modules has established the dcurrent user's identity as valid. At This piont ,the user's crenditials have been validated.

18-Application_AuthorizeRequest: Fired when the security modules has verified that the user can access resources.

Monday, November 1, 2010

Short cut key in asp.net

File
1. New Project (Ctrl+Shift+N )
2. Open Project/Solution (Ctrl+Shift+O)
3. Open File (Ctrl+O)
4. Save (Ctrl+S)
5. Save As (Ctrl+Shift+S)
6. Print (Ctrl+P)
 
Edit
7. Undo (Ctrl+Z)
8. Redo (Ctrl+Y)
 
9. Cut (Ctrl+X)
10. Copy (Ctrl+C)
11. Paste (Ctrl+V)
12. Cycle Clipboard Ring (Ctrl+Shift+V)
13. Select All (Ctrl+A)
14. Quick Find (Ctrl+F)
 
15. Quick Replace (Ctrl+H)
16. Find in Files (Ctrl+Shift+F)
17. Replace in Files (Ctrl+Shift+H)
18. Find Symbol (Alt+F12)
 
19. Format Document (Ctrl+E,D)
20. Format Selection (Ctrl+E,F)
21. Make Uppercase (Ctrl+Shift+U)
22. Make Lowercase (Ctrl+U)
23. Delete Horizontal White Space (Ctrl+E, \)
24. View White Space (Ctrl+E,S)
25. Word Wrap (Ctrl+E,W)
26. Incremental Search (Ctrl+I)
27. Comment Selection (Ctrl+E,C)
28. Uncomment Selection (Ctrl+E,U)
 
29. Toggle Bookmark (Ctrl+B,T)
30. Enable Bookmark (Ctrl+B,E)
31. Previous Bookmark (Ctrl+B,P)
32. Next Bookmark (Ctrl+B, N)
33. Clear Bookmarks (Ctrl+B,C)
34. Add Task List Shortcut (Ctrl+E,T)
 
35. Hide Selection (Ctrl+M, Ctrl+H)
36. Toggle Outlining Expansion (Ctrl+M,M)
37. Toggle All Outlining (Ctrl+M,L)
38. Stop Outlining (Ctrl+M,P)
39. Stop Hiding Current (Ctrl+M, Ctrl+U)
 
40. Generate Method Stub (Ctrl+K,M)
41. List Members (Ctrl+K,L)
42. Parameter Info (Ctrl+K,P)
43. Complete Word (Ctrl+K,W)
44. Insert Snippet (Ctrl+K,X)
45. Surround With (Ctrl+K,S)
 
View
46. Code (F7)
47. Designer (Shift+F7)
48. Server Explorer (Ctrl+W,L)
49. Class View (Ctrl+W,C)
50. Code Definition Window (Ctrl+W,D)
51. Object Browser (Ctrl+W,J)
52. Error List (Ctrl+W,E)
53. Output (Ctrl+W,O)
54. Properties Window (Ctrl+W,P)
55. Task List (Ctrl+W,T)
56. Toolbox (Ctrl+W,X)
 
57. Find Symbol Results (Ctrl+W,Q)
58. Bookmark Window (Ctrl+W,B)
59. Command Window (Ctrl+W,A)
60. Document Outline (Ctrl+W,U)
61. Resource View (Ctrl+W,R)
62. Macro Explorer (Alt+F8)
63. Web Browser (Ctrl+W,W)
 
64. Full Screen (Shift+Alt+Enter)
65. Pending Checkins (Ctrl+W,G)
66. Navigate Backward (Ctrl+-)
67. Navigate Forward (Ctrl+Shift+-)
68. Property Pages (Shift+F4)
 
Refactor
69. Rename (F2)
70. Extract Method (Ctrl+R,M)
71. Encapsulate Field (Ctrl+R,E)
72. Promote Local Variable to Parameter (Ctrl+R,P)
73. Remove Parameters (Ctrl+R,V)
74. Reorder parameters (Ctrl+R,O)
 
Website
75. Add New Item (Ctrl+Shift+A)
76. Add Existing Item (Shift+Alt+A)
 
Build
77. Build Solution (F6)
78. Build Web Site (Shift+F6)
 
Debug
79. Breakpoints (Ctrl+D,B)
80. Immediate (Ctrl+D,I)
 
81. Start Debugging (F5)
82. Start without Debugging (Ctrl+F5)
83. Exceptions (Ctrl+D,E)
84. Step Into (F11)
85. Step Over (F10)
86. Break at Function (Ctrl+D,N)
87. Delete All Breakpoints (Ctrl+Shift+F9)
 
Tools
88. Attach to Process (Ctrl+Alt+P)
89. Code Snippets Manager (Ctrl+K, Ctrl+B)
 
90. Run TemporaryMacro (Ctrl+Shift+P)
91. Record TemporaryMacro (Ctrl+Shift+R)
 
92. Macro Explorer (Alt+F8)
93. Macros IDE (Alt+F11)
 
Help
94. How Do I (Ctrl+F1,H)
95. Search (Ctrl+F1,S)
96. Contents (Ctrl+F1,C)
97. Index (Ctrl+F1,I)
98. Help Favourites (Ctrl+F1,F)
99. Dynamic Help (Ctrl+F1,D)
100. Index Results (Ctrl+F1,T)

How can ues HTMLEncode

 cmd.Parameters.Add("@e6", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox6.Text);
            cmd.Parameters.Add("@e7", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox7.Text);
            cmd.Parameters.Add("@e8", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox8.Text);
            cmd.Parameters.Add("@e9", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox9.Text);

How can put condition in aspx page

<table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                    <% if (Convert.ToInt16(Request["ID"]) == 4)
                       {%>

                   
                      <td  height="42" valign="middle" class="greyred"><a href="index.aspx?ID=4">Promotions</a></td>
                      <% } if (Convert.ToInt16(Request["ID"]) == 1 || Convert.ToInt16(Request["ID"]) == 2 || Convert.ToInt16(Request["ID"]) == 3 || Convert.ToInt16(Request["ID"]) == 5 )
                         { %>
                      <td  height="42" valign="middle" class="grey"><a href="index.aspx?ID=4" >Promotions</a></td>
                      <%}
                        else if (Convert.ToInt16(Request["ID"]) != 4)
                        {%>
                         
                       <td height="42" bgcolor="#e5e5e5" class="greyred"><a href="index.aspx?ID=4">Promotions</a></td>
                       <%}%>
                    </tr>
                    <tr>
                      <td bgcolor="#e5e5e5"><img src="images/dot.jpg" width="213" height="1" /></td>
                    </tr>
                    <tr>
                     <% if(Convert.ToInt16(Request["ID"]) == 1) {%>                       <td height="42" bgcolor="#e5e5e5" class="greyred"><a href="index.aspx?ID=1">New Arrivals </a></td>
                     <% } else { %>
                      <td height="42" bgcolor="#e5e5e5" class="grey"><a href="index.aspx?ID=1">New Arrivals </a></td>
                       <%}%>
                    </tr>
                    <tr>
                      <td bgcolor="#e5e5e5"><img src="images/dot.jpg" width="213" height="1" /></td>
                    </tr>
                    <tr>
                     <% if(Convert.ToInt16(Request["ID"]) == 2) {%>
                      <td height="42" bgcolor="#e5e5e5" class="greyred"><a href="index.aspx?ID=2">Best Sellers </a></td>
                     <% } else { %>
                      <td height="42" bgcolor="#e5e5e5" class="grey"><a href="index.aspx?ID=2">Best Sellers </a></td>
                     <%}%>
                    </tr>
                    <tr>
                      <td bgcolor="#e5e5e5"><img src="images/dot.jpg" width="213" height="1" /></td>
                    </tr>
                    <tr>
                     <% if(Convert.ToInt16(Request["ID"]) == 3) {%>
                      <td height="42" bgcolor="#e5e5e5" class="greyred"><a href="index.aspx?ID=3">Coming Soon </a></td>
                    <% } else { %>
                      <td height="42" bgcolor="#e5e5e5" class="grey"><a href="index.aspx?ID=3">Coming Soon </a></td>
                         <%}%>
                    </tr>
                    <tr>
                      <td bgcolor="#e5e5e5"><img src="images/dot.jpg" width="213" height="1" /></td>
                    </tr>
                    <tr>
                    <% if(Convert.ToInt16(Request["ID"]) == 5) {%>
                      <td height="42" bgcolor="#e5e5e5" class="greyred"><a href="index.aspx?ID=5">Offers</a></td>
                      <% } else { %>
                       <td height="42" bgcolor="#e5e5e5" class="grey"><a href="index.aspx?ID=5">Offers</a></td>
                            <%}%>
                    </tr>
                </table>