Friday 29 November 2013

HOw to Clear Cache,Cookies and History of All Browser in C#.net on Button Click

Use this code on your button click event:

protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Session["AEmail"] = null;
            Session.Clear();
            ClearCache();
            clearchachelocalall();
            Response.Redirect("../Default.aspx");

        }
        public static void ClearCache()
        {
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            HttpContext.Current.Response.Cache.SetExpires(DateTime.Now);
            HttpContext.Current.Response.Cache.SetNoServerCaching();
            HttpContext.Current.Response.Cache.SetNoStore();
            HttpContext.Current.Response.Cookies.Clear();
            HttpContext.Current.Request.Cookies.Clear();
        }

        private void clearchachelocalall()
        {
            string GooglePath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Google\Chrome\User Data\Default\";
            string MozilaPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Mozilla\Firefox\";
            string Opera1 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Opera\Opera";
            string Opera2 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Opera\Opera";
            string Safari1 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Apple Computer\Safari";
            string Safari2 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Apple Computer\Safari";
            string IE1 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Microsoft\Intern~1";
            string IE2 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Microsoft\Windows\History";
            string IE3 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Microsoft\Windows\Tempor~1";
            string IE4 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Microsoft\Windows\Cookies";
            string Flash = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Macromedia\Flashp~1";

            //Call This Method ClearAllSettings and Pass String Array Param
            ClearAllSettings(new string[] { GooglePath, MozilaPath, Opera1, Opera2, Safari1, Safari2, IE1, IE2, IE3, IE4, Flash });
           
        }

        public void ClearAllSettings(string[] ClearPath)
        {
            foreach (string HistoryPath in ClearPath)
            {
                if (Directory.Exists(HistoryPath))
                {
                    DoDelete(new DirectoryInfo(HistoryPath));
                }

            }
        }

        void DoDelete(DirectoryInfo folder)
        {
            try
            {

                foreach (FileInfo file in folder.GetFiles())
                {
                    try
                    {
                        file.Delete();
                    }
                    catch
                    { }

                }
                foreach (DirectoryInfo subfolder in folder.GetDirectories())
                {
                    DoDelete(subfolder);
                }
            }
            catch
            {
            }
        }

Thursday 21 November 2013

HOw To Call URL API for SMS sending using function in C#.NET

Copy & Paste this code and call this function anywhere you use to use API:


 public void SendSMS()
        {
            //HTTP connection
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("your url API");
            //Get response from Ozeki NG SMS Gateway Server and read the answer
            HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
            System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
            string responseString = respStreamReader.ReadToEnd();
            respStreamReader.Close();
            myResp.Close();

        }

Friday 15 November 2013

Play All type of Video files in GridView with Literal Control using C#

Follow the instructions:

1.)  First Select asp Literal Control from Toolbox.

<asp:GridView ID="GridView1" runat="server" GridLines="None" ShowHeader="False" Width="100%"
                        AutoGenerateColumns="False" AllowPaging="true" PageSize="3" OnPageIndexChanging="GridView1_PageIndexChanging">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <table style="width: 100%" cellpadding="5px">
                                        <tr>
                                            <td valign="top">
                                                <h2 style="text-align: left; color: #771212">
                                                    <%#Eval("Title")%></h2>
                                                <hr />
                                                <div style="font-size: 13px; color: Gray; text-align: right">
                                                    Posted on <%#Eval("PostingDate")%></div>
                                                <p style="font-size: 15px; color: Black">
                                                    <div style="width: 280px; height: 220px; float: left; text-align:left">
                                                        <asp:Label ID="lblvideo" runat="server" Visible="false"><%#Eval("VedioFile")%>.<%#Eval("OriginalFileExtn") %></asp:Label>
                                                        
                                                        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
                                                    </div>
                                                    <%#Eval("Description")%></p>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First" PreviousPageText="Previous"
                            NextPageText="Next" LastPageText="Last" />
                    </asp:GridView>

2.)  Copy and paste this code to your code file on GridView Binding


DataTable dt = App.GetDataTable("Select * from Blog order by PostingDate DESC");
            GridView1.DataSource = dt;
            GridView1.DataBind();
            foreach (GridViewRow gvrow in GridView1.Rows)
            {
                Label vurl = (Label)gvrow.FindControl("lblvideo");
                Literal Literal1 = (Literal)gvrow.FindControl("Literal1");
                string myobj = "";
                if (vurl.Text != "" && vurl.Text != null)
                {
                    myobj += "<video width='250' height='200' controls='controls' data-setup='{}'>";
                    myobj += "<source src='File/BlogFile/" + vurl.Text + "' type='video/ogg' />";
                    myobj += "Your browser does not support video";
                    myobj += "</object>";
                    myobj += "</video>";
                }
                else
                {
                    myobj = "<img src='File/BlogFile/blogging.jpg' width='250' height='200'/>";
                }
                Literal1.Text = myobj;

            }