Upload Image by external URL in asp.net

Task: Upload Image using external URL on our website using asp.net.

Description: Sometime we need to upload image option using URL of image(from some external resources). So that we need not to download it and then upload in our website & also need not to use external image link in our website. This code create new image in your website folder(here i used yourfolder).
We can also use it for Data-scrapping(Read Content/images from another website).
We can Resize it also. In older post I describe the resize image with maintain aspect ration here ->  Upload & Resize Image



// Code Start //


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

  public void saveimage(string imageURL)
    {
        Stream imageStream = new WebClient().OpenRead(imageURL);
        System.Drawing.Image img = System.Drawing.Image.FromStream(imageStream);
        string path = Server.MapPath("yourfolder") + "\\test.jpg";
        img.Save(path);
    }



// Code End//

How Convert GridView to Word/Excel Asp.Net C# Code

Task : How convert a gridview to Word Document or in Excel Sheet using asp.net/c#  code.

Description: Some time we need to generate different kind of reports & need to save it in Excel or word Document for Local Reference, Or sending to other's. So here I create a code for achieve this task the first one is conversion data into Excel & second one is for Word Document.

// For pdf converstion we can use third party dll like ITextSharp


C# Code : For GridView To Excel

 protected void btn_excel_Click(object sender, EventArgs e)
    {
          string attachment = "attachment; filename=myreport.xls";
          Response.Cache.SetCacheability(HttpCacheability.NoCache);
          Response.AddHeader("content-disposition", attachment);
          Response.ContentType = "application/ms-excel";
          StringWriter swriter = new StringWriter();
          HtmlTextWriter htmlwriter = new HtmlTextWriter(swriter);
 
          // Create a form to contain the gridview(MyGridView)
          HtmlForm mynewform = new HtmlForm();
          MyGridView.Parent.Controls.Add(mynewform);
          mynewform.Attributes["runat"] = "server";
          mynewform.Controls.Add(MyGridView);
          mynewform.RenderControl(htmlwriter);
          Response.Write(swriter.ToString());
          Response.End();
    }


C# Code : For GridView To Word

    protected void btn_word_Click(object sender, EventArgs e)
    {
          Response.AddHeader("content-disposition""attachment;filename=myreport.doc");
          Response.Cache.SetCacheability(HttpCacheability.NoCache);
          Response.ContentType = "application/vnd.word";
          System.IO.StringWriter swriter = new System.IO.StringWriter();
          System.Web.UI.HtmlTextWriter htmlwriter = new HtmlTextWriter(swriter);
 
          // Create a form to contain the gridview(MyGridView)
          HtmlForm mynewform = new HtmlForm();
          MyGridView.Parent.Controls.Add(mynewform);
          mynewform.Attributes["runat"] = "server";
          mynewform.Controls.Add(MyGridView);
          mynewform.RenderControl(htmlwriter);
          Response.Write(swriter.ToString());
          Response.End();
    }

create update delete xml in csharp asp.net


//How to create xml file using c#.net asp.net code
//Append Node/ Modify Node in XML using c#.net asp.net
//
using System.Xml;
using System.IO;
 protected void Button1_Click(object sender, EventArgs e)

{
  string filepath = MapPath("xml/XMLFile3.xml"); // path of xml where we want to save it
   create(filepath);
}

private void create(string filepath)    // filepath is path where we want to save xml file
{
   string xml = @"<?xml version='1.0' encoding='utf-8'?>
                    <ParentXMLNode>
                    <Header>
                           <xmlnode1>value1</xmlnode1>
                           <xmlnode2>value2</xmlnode2>
                    </Header>
                    <xmlnode3>value3</xmlnode3>
                    <xmlnode4>value4</xmlnode4>  
                    <Message>
                        <xmlnode5></xmlnode5>
                        <xmlnode5></xmlnode5>
                        <xmlnode6>
                               <Node1></Node1>
                        </xmlnode6>
                     </Message>
                    </ParentXMLNode>";

        XmlDocument docConfig = new XmlDocument();
        docConfig.LoadXml(xml);
        Literal1.Text = "<XMP>" + xml + "</XMP>";
        docConfig.Save(filepath);
    }