Showing posts with label data extraction services. Show all posts
Showing posts with label data extraction services. Show all posts

Monday, May 29, 2017

Exporting Telerik WPF GridView to CSV, Excel and Word

As everybody knows, Windows 8 is coming very soon and now a wave of developers and companies are making a big effort to implement their products for this new platform with its new style, etc. This desktop applications are based on Windows Presentation Foundation (or WPF) that it is a computer-software graphical subsystem for rendering user interfaces in Windows-based applications. WPF employs XAML, a derivative of XML, to define and link various UI elements. WPF applications can also be deployed as standalone desktop programs, or hosted as an embedded object in a website. WPF aims to unify a number of common user interface elements, such as 2D/3D rendering, fixed and adaptive documents, typography, vector graphics, runtime animation, and pre-rendered media. These elements can then be linked and manipulated based on various events, user interactions, and data bindings. Microsoft Silverlight provides functionality that is mostly a subset of WPF to provide embedded web controls comparable to Adobe Flash. 3D runtime rendering is supported in Silverlight since Silverlight 5 
Now everybody are seeing that with the controls that Windows is giving inside of Visual Studio 2010 are not fitting their needs or to accomplish them they need more time to develop exactly what they exactly need. But, fortunately we have another options that are doing much easier our lives. They are third party controls with an huge extension of choices, as Infragistics,   DevExpress, Mindscape, Telerik, etc.

<Window x:Class="WpfApplication1.Window1"
    Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    Xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
    Xmlns:telerik = "http://schemas.telerik.com/2008/xaml/presentation"
    Xmlns:local = "clr-namespace:WpfApplication1"
    Title="Window1">
    <Grid>
        <Grid.Resources>
            <ObjectDataProvider x:Key = "Customers" 
                 ObjectType = "{x:Type local:NorthwindDataContext}" MethodName = "get_Customers">
            </ObjectDataProvider>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="100" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="10" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <ComboBox x:Name="ComboBox1" SelectedIndex="0">
            <ComboBoxItem Content="Excel"/>
            <ComboBoxItem Content="Word"/>
            <ComboBoxItem Content="Csv"/>
        </ComboBox>
        <Button Content="Export" Grid.Column="1" Click="Button_Click" />
        <telerik:RadGridView Name="RadGridView1" ShowGroupPanel="False" 
                             Grid.ColumnSpan="3" Grid.Row="2"
                             ItemsSource="{Binding Source={StaticResource Customers}}" />
    </Grid>
</Window>

After this, we have to write the code to export in the “.cs” file of the Xaml view, with the Button_Click event, that it is calling the method to export the gridview:
private void Button_Click(object sender, RoutedEventArgs e)
{
  string content = "";
  ComboBoxItem comboItem = ComboBox1.SelectedItem as ComboBoxItem;
  string selectedItem = comboItem.Content.ToString();
  if (selectedItem == "Excel")
  {
    extension = "xls";
    content = RadGridView1.ToHtml(true);
  }
  else if (selectedItem == "Word")
  {
    extension = "doc";
    content = RadGridView1.ToHtml(true);
  }
  else if (selectedItem == "Csv")
  {
    extension = "csv";
    content = RadGridView1.ToCsv(true);
  }
  string path = String.Format("Export.{0}", extension);
  if (File.Exists(path)) { File.Delete(path);
  }
  using (FileStream fs = File.Create(path))
  {
    Byte[] info = Encoding.Default.GetBytes(content);
    fs.Write(info, 0, info.Length);
  }
}

As you can see, this process is very simple and easy, but it doesn’t stop here. Telerik have an huge control collections also for another technologies, as well as, Silverlight, Ajax, ASP .NET, Mobilphones and for the most recent Metro Styles of Windows 8 for the new Visual Studio 2012.
I add also the project example to this post to download and see with more detail how I accomplished it.
I hope I have helped you.


How to Download image from Url For Web Scraping

/// <summary> /// Function to download Image from Url
 /// </summary>
 /// URL address to download image
 /// <returns>Image</returns> 
 private Image DownloadImage(string _URL)
 {
        Image _tmpImage = null;
        Application.DoEvents();
        try
        {
                    // Open a connection
                    System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL);
                    _HttpWebRequest.AllowWriteStreamBuffering = true; 
                    // You can also specify additional header values like the user agent or the referer: (Optional)
                    _HttpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b) Gecko/20031212 Firebird/0.7+";
                    _HttpWebRequest.Referer = "http://www.google.com/";
                     // set timeout for 20 seconds (Optional)
                    _HttpWebRequest.Timeout = 20000;

                     // Request response:
                     System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse();

                     // Open data stream:
                     System.IO.Stream _WebStream = _WebResponse.GetResponseStream();

                     // convert webstream to image
                     _tmpImage = Image.FromStream(_WebStream);

                     // Cleanup
                     _WebResponse.Close();
                     _WebResponse.Close();
            }
            catch (Exception _Exception)
            {
                     // Error
                     Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
                     return null;
             }
            return _tmpImage;
 }

How to Set Internet explorer proxy from code behind

using Microsoft.Win32;

private void SetIeProxy(string Proxy)
 {
         RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
         registry.SetValue("ProxyServer", Proxy);
         registry.SetValue("ProxyEnable", 1);
 
         // These lines implement the Interface in the beginning of program
         // They cause the OS to refresh the settings, causing IP to realy update
         bool settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
         bool refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
 }

Thursday, December 29, 2011

How does Internet Data Mining Help for Businesses


Internet is becoming a vital moderate for individuals in order to carry out various kinds of companies as well as dealings as well. It's provided increase towards the work associated with various web information exploration resources as well as methods so they might much better their own primary reason for living on the web system as well as improve their own client bottom a lot more.



Web data mining services includes numerous procedures associated with accumulating as well as outlining various information through numerous web sites or even web page material or even take advantage of various sign in methods so they might determine numerous designs. By using web data-mining this gets very simple to place the possible rival, pep in the customer care support online as well as allow it to be much more clients focused.



You will find various kinds of web data mining methods including content material, utilization as well as framework exploration. Content material exploration concentrates much more about them issue that's existing on the web site which include the actual movie, sound, pictures as well as textual content. Utilization exploration targets a procedure in which the machines statement the actual elements utilized through customers with the server entry fire-dogs. This particular information assists within making a highly effective as well as a competent web site framework. Framework exploration targets the character associated with link from the web sites. This really is efficient to find away the actual commonalities in between numerous web sites.



Also called internet data mining, with the various tools and also the methods, it's possible to forecast the actual possible development inside a picky marketplace concerning a particular item. Information collecting never already been very easy and something might utilize a number of resources to collect information which as well within less complicated techniques. By using the information exploration resources, display scraping, internet cropping as well as internet moving have grown to be super easy as well as required information could be place easily right into a functional design as well as structure. Collecting information through any place in the net is becoming because easy because stating 1-2-3. Web data-mining resources consequently work predictors for the future developments how the company usually takes.
Data mining services