Learn As Much As You Can

Friday, 8 November 2013

Get RSS Feed to your Website

Hi,
Today I have Implemented this simple method to get the RSS feed from any other website. Usually this is used to get the Daily/Breaking/Latest News to your website.
So, Now i am going to explain how we can achieve this via simple coding.

<marquee behavious="scroll" direction="up" scrollamount="4" onmouseover="this.stop()" onmouseout="this.start()"> 
    <div style=" text-justify: inter-word; text-align: justify">
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1" >
            <ItemTemplate>
                <a target="_blank" href='<%# XPath("link") %>'>
                    <%# System.Web.HttpUtility.HtmlEncode(XPath("title").ToString())%></a>
               <br />
             <asp:Label runat="server" ID="lbl_desc" Text='<%#XPath("description")%>' ></asp:Label>
              <%#XPath("pubDate") %>
                <br />
                <br />
            </ItemTemplate>
        </asp:Repeater>

    </div>
    </marquee>

 <asp:XmlDataSource ID="XmlDataSource1" runat="server" 
        DataFile="http://feeds.feedburner.com/breakingtravelnews/news" 

        XPath="rss/channel/item"></asp:XmlDataSource>


Explanation:
                   In XmlDataSource => DataFile => URL where you want to get the News
                                        XPath=> rss/channed/item => these are the nodes that defined in xml file for rss after that xml has "link" "description" "title" "pubDate" that i have used in repeater to get the Data.


Happy Coding :) :)



Tuesday, 2 April 2013

Tinymce Editor in Asp.net


First Download the Source Code from the TinyMce site and then
Just Add the following code in the page where you want to show your TinyMce Editor
 <script src="tinymce/jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>
<script type="text/javascript">
    tinyMCE.init({
                   
                     // General options
                     mode: "textareas",
                     theme: "advanced",
                     width: "600",
                     height: "400",
                     encoding: "xml",
//Call the method to Browse the image from the computer
                     file_browser_callback: 'fileBrowserCallBack',
                     plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell, \
    inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste, \
    directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template, \
    wordcount,advlist,autosave",
                     setup: function(ed)
                     {
                         ed.onKeyPress.add(
                             function(ed, evt)
                             {
                             }
                             );
                     },
                     // Theme options
                     theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|, \
    justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect, \
    fontselect,fontsizeselect",

                     theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|, \
    bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor, \
    image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                     theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,\
    charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                     theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|, \
    styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
                     theme_advanced_toolbar_location: "top", theme_advanced_toolbar_align: "left",
                     theme_advanced_statusbar_location: "bottom", theme_advanced_resizing: true,
                     // Example content CSS (should be your site CSS) 
                     content_css: "css/content.css",
                     // Drop lists for link/image/media/template dialogs 
                     template_external_list_url: "lists/template_list.js", external_link_list_url: "lists/link_list.js",
                     external_image_list_url: "lists/image_list.js", media_external_list_url: "lists/media_list.js",
                     // Style formats 
                     style_formats: [
                         { title: 'Bold text', inline: 'b' },
                         { title: 'Red text', inline: 'span', styles: { color: '#ff0000'} },
                         { title: 'Red header', block: 'h1', styles: { color: '#ff0000'} },
                         { title: 'Example 1', inline: 'span', classes: 'example1' },
                         { title: 'Example 2', inline: 'span', classes: 'example2' },
                         { title: 'Table styles' },
                         { title: 'Table row 1', selector: 'tr', classes: 'tablerow1' }
                     ],
                     // Replace values for the template plugin
                     template_replace_values:
                     {
                         username: "Some User", staffid: "991234"
                     }
                 });
        // ---------This code for upload the image from your computer not from the web using url---
    function fileBrowserCallBack(field_name, url, type, win)
    {
//You need to create your own page to upload the image from the computer
        win.open('Browse.aspx', 'Browse Image', 'width=350,height=120,left=400, top=400, toolbar= no ,status=yes,location=no,resizable=no,dependent');
        win.document.forms[0].elements[field_name].value = filename;
        return false;
    }

  //----Code End for open a new window that helps to upload the image from the client computer-----------

Then Add the following 

 <textarea id="Editor_textArea" name="Editor_textArea" rows="15" cols="80" runat="server"></textarea>


//In the CS file

public string bodyHtml
    {
        get
        {
            return HttpUtility.HtmlDecode(Editor_textArea.Value);
        }
        set
        {
            Editor_textArea.Value = value;
        }
    }

Then You can use bodyHtml where ever you want it get the data from the editor and you can store it as it is as in your editor shows 


Thanx






Url ReWriting Using Url Rewriter.Net


  1. Open your web project in Microsoft Visual Studio .NET.
  2. Add a reference to the Intelligencia.UrlRewriter assembly.
  3. Open the web.config file in your web project.
  4. Add the following in the web.config file:
  5. <configuration>
  6.   <configSections>
  7.     <section name="rewriter"
                 requirePermission
    ="false"
                 type
    ="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
      </
    configSections>
     
      
    <system.web>
         
        
    <httpModules>
          
    <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
        </
    httpModules>
       
      
    </system.web>

      
    <system.webServer>

        
    <modules runAllManagedModulesForAllRequests="true">
          
    <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
        </
    modules>

        
    <validation validateIntegratedModeConfiguration="false" />

      </
    system.webServer>

      
    <rewriter>
        
    <rewrite url="~/products/(.+)" to="~/products.aspx?category=$1" />
      </
    rewriter>
      
    </configuration>
  8. And in the CS file or where ever you redirect to the page from put the text as in the url field like 
           Response.Redirect("~/products.aspx");

Thursday, 21 March 2013

Getting Value from Editor


private string StripHTML(string source)
    {
        string result = "";
        try
        {
            // Remove HTML Development formatting
            // Replace line breaks with space
            // because browsers inserts space
            result = source.Replace("\r", " ");
            // Replace line breaks with space
            // because browsers inserts space
            result = result.Replace("\n", " ");
            // Remove step-formatting
            result = result.Replace("\t", string.Empty);
            // Remove repeating speces becuase browsers ignore them
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"( )+", " ");

            // Remove the header (prepare first by clearing attributes)
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"<( )*head([^>])*>", "<head>",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(<( )*(/)( )*head( )*>)", "</head>",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "(<head>).*(</head>)", string.Empty,
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            // remove all scripts (prepare first by clearing attributes)
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"<( )*script([^>])*>", "<script>",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(<( )*(/)( )*script( )*>)", "</script>",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(<script>).*(</script>)", string.Empty,
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            // remove all styles (prepare first by clearing attributes)
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"<( )*style([^>])*>", "<style>",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(<( )*(/)( )*style( )*>)", "</style>",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "(<style>).*(</style>)", string.Empty,
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            // insert tabs in spaces of <td> tags
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"<( )*td([^>])*>(<( )*br( )*(/)*>)*", " ",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(<( )*br( )*(/)*>)*( )*</td([^>])*>(<( )*br( )*(/)*>)*", "",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            // insert line breaks in places of <BR> and <LI> tags
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(\r|\n)*<( )*br( )*(/)*>", "\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(\r|\n)*<( )*li( )*>", "\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            // insert line paragraphs (double line breaks) in place
            // if <P>, <DIV> and <TR> tags
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(\r|\n)*<( |/)*div([^>])*>", "\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(\r|\n)*<( )*tr([^>])*>", "\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(\r|\n)*<( |/)*p([^>])*>", "\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(\r|\n)*</table([^>])*>", "\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"(\r|\n)*</(ol|ul)([^>])*>", "\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            // Remove remaining tags like <a>, links, images,
            // comments etc - anything thats enclosed inside < >
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"<[^>]*>", string.Empty,
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            // replace special characters:
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @" ", " ",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"•", " * ",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"‹", "<",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"›", ">",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"™", "(tm)",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"⁄", "/",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"<", "<",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @">", ">",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"©", "(c)",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"®", "(r)",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @" ", " ",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            // Remove all others. More can be added, see
            // http://hotwired.lycos.com/webmonkey/reference/special_characters/
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  @"&(.{2,6});", string.Empty,
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            // make line breaking consistent
            result = result.Replace("\n", "\r");

            // Remove extra line breaks and tabs:
            // replace over 2 breaks with 2 and over 4 tabs with 4.
            // Prepare first to remove any whitespaces inbetween
            // the escaped characters and remove redundant tabs inbetween linebreaks
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "(\r)*( )+(\r)", "\r\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "(\r)( )+", "\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "(\t)( )+(\t)", "\t\t",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "(\t)( )+(\r)", "\t\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "(\r)( )+(\t)", "\r\t",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            // Remove redundant tabs
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "(\r)(\t)+(\r)", "\r\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            // Remove multible tabs followind a linebreak with just one tab
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "(\r)(\t)+", "\r\t",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "[\r]+", "\r",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "[ ]+", " ",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            // Thats it.
            result = result.Replace("\r", "\n");
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "[\n ]$", "",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            result = System.Text.RegularExpressions.Regex.Replace(result,
                                                                  "^[\n ]", "",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            return result;
        }
        catch
        {
            return result;
        }
    }

Friday, 15 March 2013

How to make the HTML table in C# (on the server side, values comes from the database)


 while (sqr.Read())
            {
                string partner_name = sqr.GetString(0);
                int partner_id = sqr.GetInt32(1);
                HtmlPartnerNameDiv += "<div id=" + partner_name + " class=tab_airline><a href=flights.html class=more_offers title=More Offers>More Offers" +
                                      "</a><div class=list-head><h2>" + partner_name + " Latest Fares </h2> </div><table class=home_partnerfares><thead><tr><th width=90 scope=col>" +
                                      "<strong>DESTINATIONS</strong></th><th width=113 scope=col ><strong>Travel dates </strong> </th><th width=70 scope=col><strong>Book by</strong></th>" +
                                      "<th width=38 scope=col><strong> Fare </strong></th><th width=40 scope=col><strong> More  </strong></th></tr></thead>";
                GetAllFaresByIdGridView(partner_id);
                HtmlPartnerNameDiv += HtmlTable;
            }



protected string GetAllFaresByIdGridView(int id)
    {
        string htmlStr = "";
        HtmlTable = "";
        try
        {
            using (SqlConnection conn = DataAccess.GetConnected())
            {
                SqlCommand cmd = new SqlCommand("GetAllFaresByID", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ID", id);
                cmd.Parameters.Add(new SqlParameter("@Error", SqlDbType.VarChar, 255));
                cmd.Parameters["@Error"].Direction = ParameterDirection.Output;
                cmd.Parameters.Add(new SqlParameter("@count", SqlDbType.VarChar, 255));
                cmd.Parameters["@count"].Direction = ParameterDirection.Output;
                SqlDataReader sqr = cmd.ExecuteReader();
                htmlStr += "<tbody>";
                while (sqr.Read())
                {
                    string Destination = sqr.GetString(0);
                    string Travel_From_Date = sqr.GetString(1);
                    string Travel_To_Date = sqr.GetString(2);
                    string Book_By = sqr.GetString(3);
                    int Fare = sqr.GetInt32(4);
                    htmlStr+= "<tr ><td>" + Destination + "</td>" +
                              "<td>" + Travel_From_Date + " - " + Travel_To_Date + "</td><td>" + Book_By + "</td><td class=price>&pound;" + Fare + "</td><td><a href=flights.html title=View Details>" +
                              "view &rsaquo; </a></td> </tr>";
                }
            }
        }
        catch (Exception ex)
        {
            //throw ex.Message;
        }
        htmlStr += "</tbody></table></div>";
        HtmlTable += htmlStr;
        return htmlStr;
    }

How to format the string in the title property of the image tag(values comes from the database)

using (SqlConnection conn = DataAccess.GetConnected())
            {
                SqlCommand cmd = new SqlCommand("GetImageForSlider", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader sqr = cmd.ExecuteReader();
                while (sqr.Read())
                {
                    string image_path = sqr.GetString(0);
                    string description = sqr.GetString(1);
                    string action = sqr.GetString(2);
                    HtmlImage += string.Format("<img src=\"{0}\" title=\"<h3>{1}.</h3><span class=price>{2}</span><p><br></p><a href=http://www.giftotravels.com >This is link</a>\"/>",image_path, description, action);
                }
            }


Monday, 11 March 2013

Insert, Edit, Delete, Update in GridView Using Asp.Net with C-Sharp And How to display images from database using image Path in GridView


aspx Code


<asp:GridView ID="Fare_Images_GridView" runat="server"  AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None"
                      AllowPaging="false" AllowSorting="true"
                      onrowcancelingedit="Fare_Images_GridView_RowCancelingEdit"
                      onrowediting="Fare_Images_GridView_RowEditing"
                      OnRowDeleting="Fare_Images_GridView_RowDeleting"
                      OnRowUpdating="Fare_Images_GridView_RowUpdating"
                      OnRowCommand="Fare_Images_GridView_RowCommand" >

          <AlternatingRowStyle BackColor="White" />
          <Columns>
            <asp:TemplateField Visible="false">
              <ItemTemplate>
                <asp:Label ID="lbl_image_id" runat="server" Visible="false" Text='<%# Eval("image_id") %>' ></asp:Label>
                <asp:Label ID="lbl_Partner_id" runat="server" Visible="false" Text='<%# Eval("Partner_id") %>' ></asp:Label>
                <asp:Label ID="lbl_image_name" runat="server" Visible="false" Text='<%# Eval("image_name") %>' ></asp:Label>
              </ItemTemplate>
       
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Logo">
              <ItemTemplate >
                <asp:Image ID="lbl_image_path" runat="server" ImageUrl='<%#Eval("image_path") %>' Width="70px" Height="70px" />
              </ItemTemplate>
              <EditItemTemplate>
                <asp:Image ID="lbl_image_path" runat="server" ImageUrl='<%#Eval("image_path") %>' Width="40px" Height="40px" />
                <asp:FileUpload ID="FileUploadImagePartner" FileName='<%#Eval("image_path") %>' Width="100px" runat="server" />
              </EditItemTemplate>
              <InsertItemTemplate>
                <asp:FileUpload ID="FileUploadImagePartner" FileName='<%#Eval("image_path") %>' Width="100px" runat="server" />
              </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Partner Name">
              <ItemTemplate>
                <asp:LinkButton ID="link_Partner_Name" CommandName="Partner_Name" CommandArgument='<%# Eval("Partner_id") %>' runat="server" Text='<%#Eval("Partner_Name") %>' ></asp:LinkButton>
              <%-- <asp:Label ID="lbl_Partner_Name" runat="server" Visible="true" Text='<%# Eval("Partner_Name") %>' ></asp:Label>--%>
              </ItemTemplate>
              <EditItemTemplate>
                <asp:TextBox ID="txt_Partner_Name" runat="server" Text='<%#Eval("Partner_Name") %>' Width="80px" ></asp:TextBox>
              </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Edit" ShowHeader="false">
              <ItemTemplate>
                <asp:LinkButton ID="btnedit" runat="server"
                                CommandName="Edit" Text="Edit" ></asp:LinkButton>
              </ItemTemplate>
       
              <EditItemTemplate>
                <asp:LinkButton ID="btndelete" runat="server"
                                CommandName="Delete" Text="Delete" OnClientClick="return confirm('This will delete your all Fares.Are you sure you want to delete? ');" ></asp:LinkButton>
                <asp:LinkButton ID="btnupdate" runat="server"
                                CommandName="Update" Text="Update" ></asp:LinkButton>
                <asp:LinkButton ID="btncancel" runat="server"
                                CommandName="Cancel" Text="Cancel"></asp:LinkButton>
              </EditItemTemplate>
            </asp:TemplateField>
          </Columns>
          <EditRowStyle BackColor="white" /><%--#2461BF--%>
          <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
          <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
          <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
          <RowStyle BackColor="#EFF3FB" HorizontalAlign="Center" />
          <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
          <SortedAscendingCellStyle BackColor="#F5F7FB" />
          <SortedAscendingHeaderStyle BackColor="#6D95E1" />
          <SortedDescendingCellStyle BackColor="#E9EBEF" />
          <SortedDescendingHeaderStyle BackColor="#4870BE" />
        </asp:GridView>


CS Code

//Method in the Data Access Layer
 public void FillGridView(string strProName, System.Web.UI.WebControls.GridView GridViewName)
    {
        //int status = 0;
        DataTable dt = new DataTable();
        try
        {
            using (SqlConnection conn = DataAccess.GetConnected())
            {
                SqlCommand cmd = new SqlCommand(strProName, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter sqlda = new SqlDataAdapter();
                sqlda.SelectCommand = cmd;
                sqlda.Fill(dt);
                GridViewName.DataSource = dt;
                GridViewName.DataBind();
            }
        }
        catch (Exception ex)
        {
            //throw ex.Message;
        }
    }

//Call on Presentation Layer

 protected void GetAllImagesPartner()
    {
        da.FillGridView("ShowPartnerImagesGridView", Fare_Images_GridView);
    }

 protected void Fare_Images_GridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        Fare_Images_GridView.EditIndex = -1;
        GetAllImagesPartner();
    }

    protected void Fare_Images_GridView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Fare_Images_GridView.EditIndex = e.NewEditIndex;
        GetAllImagesPartner();
    }

    protected void Fare_Images_GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string filename = "";
        string image="";
        try
        {
            FileUpload fileupload = (FileUpload)Fare_Images_GridView.Rows[e.RowIndex].FindControl("FileUploadImagePartner");
            if (fileupload.HasFile)
            {
                // string filename = Path.GetFileName(this.fileupload.PostedFile.FileName);
                filename = fileupload.FileName;
                image=filename;
                fileupload.SaveAs(Server.MapPath("~/Partner_Fare_Images/" + filename));
            }
            else
            {
                Label image_name = (Label)Fare_Images_GridView.Rows[e.RowIndex].FindControl("lbl_image_name");
                image=image_name.Text;
                //filename = image_name.ToString();
            }
            Label lbl_Partner_Id = (Label)Fare_Images_GridView.Rows[e.RowIndex].FindControl("lbl_Partner_id");
            Label lbl_image_Id = (Label)Fare_Images_GridView.Rows[e.RowIndex].FindControl("lbl_image_id");
            TextBox txt_Partner_Name = (TextBox)Fare_Images_GridView.Rows[e.RowIndex].FindControl("txt_Partner_Name");

            using (SqlConnection con = DataAccess.GetConnected())
            {
                SqlCommand cmd = new SqlCommand("UpdatePartnerImage", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Partner_Id", lbl_Partner_Id.Text);
                cmd.Parameters.AddWithValue("@Image_Id", lbl_image_Id.Text);
                cmd.Parameters.AddWithValue("@Image_Path", "Partner_Fare_Images/" + image);
                //cmd.Parameters.AddWithValue("@Image_Path", );
                cmd.Parameters.AddWithValue("@Partner_Name", txt_Partner_Name.Text);
                cmd.Parameters.AddWithValue("@image_name", image);
                cmd.ExecuteNonQuery();
                Fare_Images_GridView.EditIndex = -1;
                GetAllImagesPartner();
            }
        }
        catch (Exception ex)
        { 
        }
    }

    protected void Fare_Images_GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            GridViewRow row = Fare_Images_GridView.Rows[e.RowIndex];
            Label Image_Id = (Label)row.FindControl("lbl_Image_id");
            Label Partner_Id = (Label)row.FindControl("lbl_Partner_id");
            using (SqlConnection con = DataAccess.GetConnected())
            {
                SqlCommand cmd = new SqlCommand("deletePartnerFullData", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Image_Id", Image_Id.Text);
                cmd.Parameters.AddWithValue("@Partner_Id", Partner_Id.Text);
                cmd.ExecuteNonQuery();
                con.Close();
                GetAllImagesPartner();
            }
        }
        catch (Exception ex)
        { 
        }
    }

    protected void Fare_Images_GridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Partner_Name")
        {
            using (SqlConnection con = DataAccess.GetConnected())
            {
                try
                {
                    int rowindex = Convert.ToInt32(e.CommandArgument);
                    GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
                    LinkButton Partner_Name = (LinkButton)row.FindControl("link_Partner_Name");
                    //Label Partner_Id = (Label)row.FindControl("lbl_Partner_Id");
                    hdn_Add_Fare_Partner.Value = Partner_Name.Text;
                    hdn_Add_Fare_Id.Value = rowindex.ToString();
                    lbl_Add_Fare.Text = "";
                    lbl_Add_Fare.Text = "Add Fare For " + hdn_Add_Fare_Partner.Value;
                    GetAllFaresById(Convert.ToInt32(hdn_Add_Fare_Id.Value));
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message.ToString());
                }
                finally
                {
                    con.Close();
                }
            }
        }
    }

Sunday, 10 March 2013

How to make a Folder/Directory in Asp.net with C-Sharp

http://aspnetgeeks.blogspot.com/p/aspnet.html

aspx Code


<div style=" float:left; position:relative; clear:left">
       <%-- <h2 style="color:Navy">asp.net example: create directory</h2> --%>
        <asp:Label  ID="Label1" runat="server" Font-Size="Medium" ForeColor="SeaGreen"></asp:Label>
        <br />
        <asp:Label  ID="Label2" runat="server" Font-Size="20px" ForeColor="Red"></asp:Label>
         <asp:Label  ID="Label4" runat="server" Font-Size="20px" ForeColor="Red"></asp:Label>
        <br /><br />
        <asp:Label ID="Label3" runat="server" Text="Directory Name"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br /><br />
        <asp:Button ID="btnCreateDirectory" runat="server" Font-Bold="true" ForeColor="HotPink" Text="Create Directory" OnClick="btnCreateDirectory_Click"  />
     
    </div>


 Code Behind File

protected void btnCreateDirectory_Click(object sender, System.EventArgs e)
    {
        string appPath = Request.PhysicalApplicationPath.ToString();

        DirectoryInfo newDirectory = new DirectoryInfo(appPath + TextBox1.Text);
        string path = Server.MapPath("~/" + TextBox1.Text);
        try
        {
            if (!Directory.Exists(path))
            {
                newDirectory.Create();
                SqlConnection conn = DataAccess.GetConnected();
                SqlCommand cmd = new SqlCommand("AddCheckFolder", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@folder_name",TextBox1.Text);
                cmd.Parameters.AddWithValue("@CreatedDate",DateTime.Now.ToString());
                int result= cmd.ExecuteNonQuery();
                if (result != 0)
                {
                    Label4.Text = "Folder Added in Database Successfully";
                }
                else
                {
                    Label4.Text = "Unfortunately Folder Can't added in Database";
                }
            }
            else
            {
                Label2.Text = "Folder Already Exists";
            }
            
        }
        catch (Exception ex)
        {
            Label2.Text = "An error occured when creating a directory!";
        }

Monday, 12 March 2012

Benefits of Duaa (Part -2)

  • Abu Hurairah  narrates from Rasool-Allah , "Three duaas are such in which there is no doubt of their acceptance: 
    • 1) Father's duaa
    •  2) Traveler's duaa
    •  3) Duaa of the oppressed(mazloom)". (Timizi, Ibne Majah)
  • Abu Hurairah  narrates from Rasool-Allah , "Three types of people's duaas are not rejected: 
    • 1) At the time of iftar the person who has fasted
    •  2) Adil ruler's duaa
    •  3) The duaa of the oppressed (mazloom) . Allah raises the duaa of the oppressed (mazloom)  on the clouds and the doors of heaven are opened for it and Allah says, "Oath(qasam) of MY Majesty(jalal) and Honour!(izzat) I will help and aid you. Even though if the help is after few days." (Tirmizi)
  • Abu Hurairah  narrates from Rasool-Allah , "When anyone of you does duaa then don't say "Oh Allah! Forgive me if you want", "Have mercy on me if you want", "Give me subsistence(rizq) if you wish" rather believe completely that HE will do whatever HE wishes. Nobody can force HIM." (Bukhari)
  • Abu Hurairah  narrates from Rasool-Allah , "Allah excepts the duaa of a person till the duaa is not related to sin(gunah) or breaking of some relation and until he does not haste(quickness) in that duaa. The people (May Allah be happy with them) asked, "Oh Rasool-Allah! What is meant by haste (quickness)?" He  replied, "That the person say "I did duaa again and again but my duaa wasn't accepted and afterwards he becomes hopeless and leaves the duaa. This is called haste (quickness) ." (Muslim)
  • Jabir  narrates from Rasool-Allah , "Don't do Bad-duaa [against] yourself, your wealth, or for your children. May it be the moment of acceptance in the court of Allah and your Bad-duaa be accepted. (Muslim)
  • Boraidah  narrates that Rasool-Allah  heard a man performing duaa like so    so He  said, "He [the man] has performed duaa with the Ism-e-Azam and when Allah is asked through the Ism-e-Azam, Allah grants and when duaa is performed with it HE accepts it." (Tirmizi and Abu Dawood)
  • Asma binte Yazeed (Radi Allahu Anha) narrates from Rasool-Allah , "Ism-e-Azam is in these two ayahs  and in the beginning of Ale-Imran . " (Tirmizi and Abu Dawood)
  • Abu Hurairah  narrates from Rasool-Allah , "Saying  is dearer to me than this world and all that is in it." (Mislim)
  • Abu Hurairah  narrates from Rasool-Allah , "Whoever said  hundred times in one day his sins are erased even if they are equal to the foam of the sea." (Muslim and Bukhari)
  • Abu Hurairah  narrates from Rasool-Allah , "Every Prophet had a special duaa which is accepted in the court of Allah. All Prophets were in quick in their duaas. On the day of Judgment, for the intercession of my Ummah, I have saved my duaa. My duaa will reach to every person in my ummah, who did not make any partners with Allah. (Muslim)    

Wednesday, 29 February 2012

Benefits of Duaa (Part -1)


  • Numan bin Basheer  narrates from Rasool-Allah , "Duaa is ibadat." Then He  read this ayat . (Tirmizi, Abu Dawod, and Ibn-e-Majah)
  • Abu Hurairah  narrates from Rasool-Allah , "In the court of Allah, there is no greater thing than duaa" (Ibn-e-Majah)
  • Abdullah bin Umar  narrates from Rasool-Allah  ," Among whatever has been descended(Naazil) and whatever has not been descended (Naazil)  Duaa is beneficial of all. Oh people of Allah! Assume Duaa a must for yourselves. (Tirmizi)
  • Abdullah bin Umar  from Rasool-Allah , "For whoever the door of duaa opened, for him the doors of mercy are opened. Whatever duaa is asked from Allah the best duaa is for well-being and safety among them." (Tirmizi)
  • Abu Hurairah  narrates from Rasool-Allah , "Allah is extremely displeased(nazaz) with the person who doesn't do duaa to Allah". (Tirmizi)
  • Salman  narrates from Rasool-Allah , "Your Rab is modest(humble) and kind. A person raise his hands in HIS court and HE leave them empty, Allah shies(Haya) from it." (Tirmizi and Abu Dawood)
  • Jabir  narrates from Rasool-Allah , "Whoever does duaa to Allah, Allah fulfills his seeking(needs) or in exchange averts(turn away) misfortune(mishap) until the duaa is not related to sin or breaking some relation." (Tirmizi)
  • Abu Hurairah  narrates from Rasool-Allah , "Do duaa to Allah with this confidence that HE will accept it and know this well that Allah doesn't accept the duaa done with a negligent and careless heart. (Tirmizi)
  • Salman Farsi  narrates from Rasool-Allah , "Duaa turns away destiny(kismat) and good deeds lengthen(make longer) age. (Tirmizi)
  • Umar  narrates that, "Whenever Rasool-Allah  raised his hands for duaa He  did not put down them down until HE  took both hands over his face." (Tirmizi)
  • Abdullah bin Umar  narrates from Rasool-Allah , "Duaa for a person not present is accepted quickly by Allah." (Tirmizi and Abu Dawood)



                                                                                         Note: Next part will be published soon
                                                                                                                    Please keep visiting