<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Visual Studio Archives - Nerd Corner</title>
	<atom:link href="https://nerd-corner.com/category/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerd-corner.com/category/visual-studio/</link>
	<description>Craft your dreams!</description>
	<lastBuildDate>Thu, 18 May 2023 14:12:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://nerd-corner.com/wp-content/uploads/2019/10/cropped-LogoNerdCorner-2-32x32.png</url>
	<title>Visual Studio Archives - Nerd Corner</title>
	<link>https://nerd-corner.com/category/visual-studio/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Enable TensorFlow GPU under Windows</title>
		<link>https://nerd-corner.com/enable-tensorflow-gpu-under-windows/</link>
					<comments>https://nerd-corner.com/enable-tensorflow-gpu-under-windows/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Tue, 09 May 2023 21:40:43 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Deep Learning]]></category>
		<category><![CDATA[GPU]]></category>
		<category><![CDATA[graphics card]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[ML]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Step by step guide]]></category>
		<category><![CDATA[Tensorflow]]></category>
		<category><![CDATA[TensorFlow GPU]]></category>
		<category><![CDATA[Tensorflow guide]]></category>
		<category><![CDATA[user guide]]></category>
		<category><![CDATA[Windows]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=1376</guid>

					<description><![CDATA[<p>I am currently working on a hobby project where I want to translate German sentences into Bavarian using AI, for example on the website Dialektl.com. &#8230; </p>
<p>The post <a href="https://nerd-corner.com/enable-tensorflow-gpu-under-windows/">Enable TensorFlow GPU under Windows</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I am currently working on a hobby project where I want to translate German sentences into Bavarian using AI, for example on the website <a href="http://dialektl.com" target="_blank" rel="noopener">Dialektl.com</a>. I am working with Tensorflow, an open source platform for machine learning and deep learning. Tensorflow is one of the most widely used libraries for Deep Learning because it offers a wide range of features and a very active developer community. For almost all machine learning models, the training process is extremely computationally expensive. To increase the speed of the training process, it is recommended to use the computer&#8217;s graphics card (GPU) instead of the processor (CPU).</p>
<p>My naive thought was that Tensorflow would automatically use the GPU. However, you first have to follow the step-by-step instructions below in order for Tensorflow to recognise and use the GPU at all.</p>
<p><em><strong>You might also be interested in:</strong> <a href="https://nerd-corner.com/tensorflow-js-vs-tensorflow-python/">Should I use Tensorflow.js or Tensorflow (Python)?</a></em></p>
<p><strong>DISCLAIMER: As of version 2.11, Tensorflow no longer supports GPUs under Windows! Either change the operating system or downgrade Tensorflow to version 2.10. In addition, a graphics card from NVIDIA is required!</strong></p>
<h3>1. Checking the desired CUDA and cuDNN versions</h3>
<p>First, you should find out which CUDA and cuDNN version you need for TensorFlow. The website lists all versions of Tensorflow and the desired CUDA versions or cuDNN versions:<a href="https://www.tensorflow.org/install/source_windows#gpu"> https://www.tensorflow.org/install/source_windows#gpu</a></p>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-1372 zoooom" src="https://nerd-corner.com/wp-content/uploads/2023/05/tensorflow_requirements.png" alt="tensorflow requirements" width="1120" height="562" srcset="https://nerd-corner.com/wp-content/uploads/2023/05/tensorflow_requirements.png 1128w, https://nerd-corner.com/wp-content/uploads/2023/05/tensorflow_requirements-300x151.png 300w, https://nerd-corner.com/wp-content/uploads/2023/05/tensorflow_requirements-1024x514.png 1024w, https://nerd-corner.com/wp-content/uploads/2023/05/tensorflow_requirements-768x385.png 768w" sizes="(max-width: 1120px) 100vw, 1120px" /></p>
<h2>2. Checking your own graphics card</h2>
<p>As already mentioned in the disclaimer, the graphics card must be from NVIDIA. On the website <a href="https://developer.nvidia.com/cuda-gpus" target="_blank" rel="noopener">https://developer.nvidia.com/cuda-gpus</a> you can search for your own GPU and check the &#8220;Compute Capability&#8221;. The minimum requirement for Tensorflow is a value of 3.5, but this is fulfilled by all current graphics cards.</p>
<p><img decoding="async" class="aligncenter wp-image-1371 zoooom" src="https://nerd-corner.com/wp-content/uploads/2023/05/cuda-architectures.png" alt="cuda architectures" width="1120" height="158" srcset="https://nerd-corner.com/wp-content/uploads/2023/05/cuda-architectures.png 1129w, https://nerd-corner.com/wp-content/uploads/2023/05/cuda-architectures-300x42.png 300w, https://nerd-corner.com/wp-content/uploads/2023/05/cuda-architectures-1024x144.png 1024w, https://nerd-corner.com/wp-content/uploads/2023/05/cuda-architectures-768x108.png 768w" sizes="(max-width: 1120px) 100vw, 1120px" /></p>
<h2>3. Installing the latest NVIDIA drivers</h2>
<p>To enable the GPU for TensorFlow, the latest NVIDIA drivers must be installed. Simply go to the NVIDIA website and download the latest driver for your graphics card.</p>
<h2>4. Install Visual Studio (optional)</h2>
<p>In TensorFlow, some parts of the library have been written in C++ to maximise performance. Therefore, installing Visual Studio can help improve the compatibility and performance of TensorFlow:<a style="font-size: 1.125rem; color: midnightblue; outline: 0px;" href="https://visualstudio.microsoft.com/de/vs/"> https://visualstudio.microsoft.com/de/vs/</a></p>
<p><img decoding="async" class="aligncenter wp-image-1370 zoooom" src="https://nerd-corner.com/wp-content/uploads/2023/05/vs-studio-download.png" alt="Visual studio installer" width="690" height="304" srcset="https://nerd-corner.com/wp-content/uploads/2023/05/vs-studio-download.png 694w, https://nerd-corner.com/wp-content/uploads/2023/05/vs-studio-download-300x132.png 300w" sizes="(max-width: 690px) 100vw, 690px" /></p>
<p>It is sufficient to select individual components here. I have selected everything with C++ in &#8220;Compiler, Buildtools and Runtimes&#8221; and also MS Build, which in turn automatically installs a few more components. All in all, however, over 25 GB!</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1369 zoooom" src="https://nerd-corner.com/wp-content/uploads/2023/05/VS-studio-components.png" alt="choose components in visual studio" width="880" height="751" srcset="https://nerd-corner.com/wp-content/uploads/2023/05/VS-studio-components.png 885w, https://nerd-corner.com/wp-content/uploads/2023/05/VS-studio-components-300x256.png 300w, https://nerd-corner.com/wp-content/uploads/2023/05/VS-studio-components-768x655.png 768w" sizes="auto, (max-width: 880px) 100vw, 880px" /></p>
<h2>5. Install CUDA Toolkit</h2>
<p>The CUDA Toolkit is a toolkit for CUDA application development provided by NVIDIA. TensorFlow requires CUDA to run on the GPU. Simply download and install the version of the CUDA toolkit requested in step 1 from the NVIDIA website: <a href="https://developer.nvidia.com/cuda-downloads">https://developer.nvidia.com/cuda-downloads</a></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1368 zoooom" src="https://nerd-corner.com/wp-content/uploads/2023/05/Cuda-toolkit-download.png" alt="download cuda toolkit" width="1130" height="889" srcset="https://nerd-corner.com/wp-content/uploads/2023/05/Cuda-toolkit-download.png 1135w, https://nerd-corner.com/wp-content/uploads/2023/05/Cuda-toolkit-download-300x236.png 300w, https://nerd-corner.com/wp-content/uploads/2023/05/Cuda-toolkit-download-1024x806.png 1024w, https://nerd-corner.com/wp-content/uploads/2023/05/Cuda-toolkit-download-768x604.png 768w" sizes="auto, (max-width: 1130px) 100vw, 1130px" /></p>
<h2>6. Installing the cuDNN libraries</h2>
<p>cuDNN is a library of deep learning primitives provided by NVIDIA. TensorFlow also requires cuDNN to run on the GPU. cuDNN is free, but you have to create an account as NVIDIA Developer: <a href="https://developer.nvidia.com/rdp/cudnn-download">https://developer.nvidia.com/rdp/cudnn-download</a></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1367 zoooom" src="https://nerd-corner.com/wp-content/uploads/2023/05/cuDNN-download.png" alt="cuDNN download" width="1710" height="875" srcset="https://nerd-corner.com/wp-content/uploads/2023/05/cuDNN-download.png 1717w, https://nerd-corner.com/wp-content/uploads/2023/05/cuDNN-download-300x154.png 300w, https://nerd-corner.com/wp-content/uploads/2023/05/cuDNN-download-1024x524.png 1024w, https://nerd-corner.com/wp-content/uploads/2023/05/cuDNN-download-768x393.png 768w, https://nerd-corner.com/wp-content/uploads/2023/05/cuDNN-download-1536x786.png 1536w" sizes="auto, (max-width: 1710px) 100vw, 1710px" /></p>
<p>After the download, the content must be unpacked. The content is moved to the &#8220;NVIDIA GPU Computing Toolkit&#8221; in the &#8220;Programs&#8221; folder. After moving, copy the file path of the &#8220;bin&#8221; folder.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1366 zoooom" src="https://nerd-corner.com/wp-content/uploads/2023/05/unzip-cuDNN.png" alt="unzip cuDNN" width="670" height="226" srcset="https://nerd-corner.com/wp-content/uploads/2023/05/unzip-cuDNN.png 673w, https://nerd-corner.com/wp-content/uploads/2023/05/unzip-cuDNN-300x101.png 300w" sizes="auto, (max-width: 670px) 100vw, 670px" /></p>
<h2>7. Set PATH variable</h2>
<p>Open the environment variables by simply typing the term into the Windows search. Then edit the system variable &#8220;path&#8221; and add a new entry with the file path of the &#8220;bin&#8221; folder from the previous step.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1365 zoooom" src="https://nerd-corner.com/wp-content/uploads/2023/05/path-variable.png" alt="Set path variable for tensorflow gpu" width="1220" height="203" srcset="https://nerd-corner.com/wp-content/uploads/2023/05/path-variable.png 1223w, https://nerd-corner.com/wp-content/uploads/2023/05/path-variable-300x50.png 300w, https://nerd-corner.com/wp-content/uploads/2023/05/path-variable-1024x170.png 1024w, https://nerd-corner.com/wp-content/uploads/2023/05/path-variable-768x127.png 768w" sizes="auto, (max-width: 1220px) 100vw, 1220px" /></p>
<h2>8. Creating a virtual environment</h2>
<p>It is recommended to install TensorFlow in a virtual environment to avoid conflicts with other Python packages. Ideally using Anaconda. Simply download and install here: <a href="https://www.anaconda.com/download">https://www.anaconda.com/download</a></p>
<p>Then start the Anaconda Navigator. Create a new environment under Environments &gt; Create. Then click on Home again and launch an existing Python IDE from here. Additional IDEs such as PyCharm should also be automatically displayed here after the download.</p>
<h2>9. Verify Tensorflow GPU support</h2>
<p>To check whether the TensorFlow GPU support was successfully detected, the Tensorflow package should first be installed in the Python IDE. But note that under Windows the GPU is only recognised up to version 2.10! In the following versions it is no longer recognised! Tensorflow 2.10 must therefore be installed.</p>
<p>Then run the following code to display a list of available GPUs:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python">import tensorflow as tf

tf.config.list_physical_devices('GPU')</pre>
<p>&nbsp;</p>
<p>The post <a href="https://nerd-corner.com/enable-tensorflow-gpu-under-windows/">Enable TensorFlow GPU under Windows</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/enable-tensorflow-gpu-under-windows/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to add custom icon pins to Google Maps Xamarin App</title>
		<link>https://nerd-corner.com/how-to-add-custom-icon-pins-to-google-maps-xamarin-app/</link>
					<comments>https://nerd-corner.com/how-to-add-custom-icon-pins-to-google-maps-xamarin-app/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Mon, 13 Apr 2020 11:51:24 +0000</pubDate>
				<category><![CDATA[App development]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[App with Google Maps]]></category>
		<category><![CDATA[custom Google Maps marker]]></category>
		<category><![CDATA[custom Google Maps pin]]></category>
		<category><![CDATA[icons on google map]]></category>
		<category><![CDATA[Xamarin]]></category>
		<category><![CDATA[Xamarin Forms]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=508</guid>

					<description><![CDATA[<p>We explained in the last post how to integrate Google Maps in a Xamarin Forms application. In this post we make a further step an &#8230; </p>
<p>The post <a href="https://nerd-corner.com/how-to-add-custom-icon-pins-to-google-maps-xamarin-app/">How to add custom icon pins to Google Maps Xamarin App</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>We explained in the <a href="https://nerd-corner.com/how-to-integrate-google-maps-in-an-app-with-xamarin/">last post</a> how to integrate Google Maps in a Xamarin Forms application. In this post we make a further step an show you how to change the standard Google Maps marker pin to custom icon pins in Google Maps.</p>
<h2>List of components</h2>
<ul>
<li>Visual Studio (free)</li>
</ul>
<h2>Setting a pin on the Google Map an choose a starting point</h2>
<p>Let&#8217;s start to put a few markers on the map. The code is pretty simple. In the &#8220;MainPage.xaml.cs&#8221; include the following using directive:</p>
<pre>using Xamarin.Forms.GoogleMaps;</pre>
<p>Then create a pin with position and label:</p>
<pre><code>Pin one = new Pin ()
{
    Label = "Pin ONE",
    Position = new position (48.1390196, 11.5744422)
};
MyMap.Pins.Add (one);</code></pre>
<p>&#8220;MyMap&#8221; is the name we have set in the &#8220;MainPage.xaml&#8221;.</p>
<p>The following code can be used to ensure that the map always opens at a specific starting point:</p>
<pre><code>MyMap.MoveToRegion (MapSpan.FromCenterAndRadius (new Position (48.1390196, 11.5744422), Distance.FromKilometers (10)));</code></pre>
<p>And this is how the app looks now:</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-495 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_standard_pins.jpg" alt="Screenshot Google Maps in App" width="310" height="620" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_standard_pins.jpg 1080w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_standard_pins-150x300.jpg 150w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_standard_pins-512x1024.jpg 512w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_standard_pins-768x1536.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_standard_pins-1024x2048.jpg 1024w" sizes="auto, (max-width: 310px) 100vw, 310px" /></p>
<h2>Add new icons</h2>
<p><span style="font-size: 1.125rem;">I downloaded two alternative icons i</span>n order to replace the red Google standard pins. I have the &#8220;castle.png&#8221; and &#8220;beer.png&#8221; icon from the website <a href="http://icons8.com">icons8.com</a>.</p>
<p>For iOS, we simply drag the two icons to the &#8220;Resources&#8221; folder in the iOS project. It should look like this:</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-510 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_iOS.jpg" alt="Add pictures to Xamarin Forms iOS project NErd Corner" width="1599" height="847" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_iOS.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_iOS-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_iOS-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_iOS-768x407.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_iOS-1536x814.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>For Android we drag the icons to the &#8220;drawable&#8221; folder under &#8220;Resources&#8221; in the Android project. For me it is unfortunately always the case that the &#8220;drawable&#8221; folder has to be created manually. Although, it is displayed normally in the Visual Studio folder structure, it actually doesn&#8217;t really exist if you search the folder on your computer. So create a new folder, where the really &#8220;drawable&#8221; folder should be and name it &#8220;drawable&#8221;. Restart Visual Studio and then add the two icons. It looks like this:</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-511 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_Android.jpg" alt="Visual Studio Xamarin how to integrate icons in the drawable folder Nerd Corner" width="1599" height="848" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_Android.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_Android-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_Android-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_Android-768x408.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Icons_Android-1536x815.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<h2>Extra step for Android users: Create a Bitmap class</h2>
<p>iOS has a clear advantage here. You don&#8217;t have to do anything for Apple phones. iOS automatically renders the icons from the &#8220;Resources&#8221; folder. For Android, however, you have one extra step, but you are almost there.</p>
<p>Create a class in the ANDROID project, name it &#8220;BitmapConfig.cs&#8221; and copy the following code:</p>
<pre><code>
using DemoGoogleMapApp.Droid;
using Xamarin.Forms.GoogleMaps;
using Xamarin.Forms.GoogleMaps.Android.Factories;
using AndroidBitmapDescriptor = Android.Gms.Maps.Model.BitmapDescriptor;
using AndroidBitmapDescriptorFactory = Android.Gms.Maps.Model.BitmapDescriptorFactory;

public sealed class BitmapConfig : IBitmapDescriptorFactory
{
    public AndroidBitmapDescriptor ToNative(BitmapDescriptor descriptor)
    {
        int iconId = 0;
        switch (descriptor.Id)
        {
            case "castle":
                iconId = Resource.Drawable.castle;
                break;
            case "beer":
                iconId = Resource.Drawable.beer;
                break;
        }
        return AndroidBitmapDescriptorFactory.FromResource(iconId);
    }
}
</code></pre>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-513 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_BitmapConfig.jpg" alt="Visual Studio Xamarin Bitmap Config for custom icon google maps pin Nerd Corner" width="1599" height="847" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_BitmapConfig.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_BitmapConfig-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_BitmapConfig-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_BitmapConfig-768x407.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_BitmapConfig-1536x814.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /><br />
You can create an extra case for each icon. We can then assign a case name to each pin on the map.</p>
<p>In the &#8220;MainActivity.cs&#8221; the Google Maps initialization also has to be changed a little bit. Add the following using directive and the new initialization code.</p>
<p>Using directive:</p>
<pre>using Xamarin.Forms.GoogleMaps.Android</pre>
<p>Initialization code:</p>
<pre><code>
var platformConfig = new PlatformConfig
{
    BitmapDescriptorFactory = new BitmapConfig()
};
Xamarin.FormsGoogleMaps.Init(this, savedInstanceState, platformConfig);
</code></pre>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-514 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-Bitmap-Config-in-Main-Activity.jpg" alt="Bitmap Config for custom google pins in main activation function android Nerd Corner" width="1599" height="848" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-Bitmap-Config-in-Main-Activity.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-Bitmap-Config-in-Main-Activity-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-Bitmap-Config-in-Main-Activity-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-Bitmap-Config-in-Main-Activity-768x408.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-Bitmap-Config-in-Main-Activity-1536x815.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>I got the idea for the &#8220;BitmapConfig.cs&#8221; from this <a href="https://medium.com/@dev.aritradas/using-custom-markers-and-latitude-longitude-bounds-in-google-maps-on-xamarin-forms-690babde96ff">post</a>.</p>
<h2>Last step: Add the custom icon pins in Google Maps app</h2>
<p>From now on you can easily set the icon image for each pin on the Google Map:</p>
<pre><code>
Pin one = new Pin()
{
    Label="Pin ONE",
    Position= new Position(48.1390196, 11.5744422),
    Icon= BitmapDescriptorFactory.FromBundle("beer"),
    Type = PinType.Place
};
</code></pre>
<p>Each icon can be used as a Google Maps Pin with the following assignment:</p>
<pre>Icon = BitmapDescriptorFactory.FromBundle ("NameOfTheCase")</pre>
<h2>Screenshots of the custom icon pins in Google Maps app</h2>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-520 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_two_end.jpg" alt="Screenshot Xamarin Forms App with custom Google Maps Pin marker image Nerd Corner" width="200" height="400" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_two_end.jpg 1080w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_two_end-150x300.jpg 150w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_two_end-512x1024.jpg 512w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_two_end-768x1536.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_two_end-1024x2048.jpg 1024w" sizes="auto, (max-width: 200px) 100vw, 200px" /> <img loading="lazy" decoding="async" class="alignleft wp-image-519 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_one_end.jpg" alt="Screenshot Xamarin Forms App with custom Google Maps Pin marker image Nerd Corner" width="200" height="400" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_one_end.jpg 1080w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_one_end-150x300.jpg 150w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_one_end-512x1024.jpg 512w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_one_end-768x1536.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_pin_one_end-1024x2048.jpg 1024w" sizes="auto, (max-width: 200px) 100vw, 200px" /> <img loading="lazy" decoding="async" class="alignleft wp-image-518 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pins.jpg" alt="Screenshot Xamarin Forms App with custom Google Maps Pin marker image Nerd Corner" width="200" height="400" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pins.jpg 1080w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pins-150x300.jpg 150w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pins-512x1024.jpg 512w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pins-768x1536.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pins-1024x2048.jpg 1024w" sizes="auto, (max-width: 200px) 100vw, 200px" /> <img loading="lazy" decoding="async" class="wp-image-517 zoooom alignleft" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pin_with_label.jpg" alt="Screenshot Xamarin Forms App with custom Google Maps Pin marker image Nerd Corner" width="200" height="400" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pin_with_label.jpg 1080w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pin_with_label-150x300.jpg 150w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pin_with_label-512x1024.jpg 512w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pin_with_label-768x1536.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_custom_pin_with_label-1024x2048.jpg 1024w" sizes="auto, (max-width: 200px) 100vw, 200px" /></p>
<h2>Download files</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/530/?tmstv=1755868896" rel="nofollow" id="download-link-530" data-redirect="false" >
	Source Code Xamarin Forms Google Maps App with custom icon</a>
</li>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/533/?tmstv=1755868896" rel="nofollow" id="download-link-533" data-redirect="false" >
	Icons</a>
</li>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/536/?tmstv=1755868896" rel="nofollow" id="download-link-536" data-redirect="false" >
	BitmapConfig.cs AndroidManifest.xml MainActivity.cs</a>
</li>
</ul>
<p>Please don&#8217;t forget to insert your Google Maps API Key in the source code.</p>
<p>&nbsp;</p>
<p>The post <a href="https://nerd-corner.com/how-to-add-custom-icon-pins-to-google-maps-xamarin-app/">How to add custom icon pins to Google Maps Xamarin App</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/how-to-add-custom-icon-pins-to-google-maps-xamarin-app/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>How to integrate Google Maps in an App with Xamarin</title>
		<link>https://nerd-corner.com/how-to-integrate-google-maps-in-an-app-with-xamarin/</link>
					<comments>https://nerd-corner.com/how-to-integrate-google-maps-in-an-app-with-xamarin/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Mon, 13 Apr 2020 10:53:42 +0000</pubDate>
				<category><![CDATA[App development]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[App with Google Maps]]></category>
		<category><![CDATA[custom Google Maps marker]]></category>
		<category><![CDATA[custom Google Maps pin]]></category>
		<category><![CDATA[Xamarin]]></category>
		<category><![CDATA[Xamarin Forms]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=491</guid>

					<description><![CDATA[<p>This post explains how to integrate Google Maps in an app. The app is a Xamarin Forms application. Xamarin is a cross platform for Android &#8230; </p>
<p>The post <a href="https://nerd-corner.com/how-to-integrate-google-maps-in-an-app-with-xamarin/">How to integrate Google Maps in an App with Xamarin</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This post explains how to integrate Google Maps in an app. The app is a Xamarin Forms application. Xamarin is a cross platform for Android and iOS. The programming language is C#. In addition to this post, <a href="https://nerd-corner.com/how-to-add-custom-icon-pins-to-google-maps-xamarin-app/">there will be a post</a>, which describes how to replace the standard Google Map pin with a custom icon.</p>
<h2>List of components</h2>
<ul>
<li>Visual Studio (free)</li>
</ul>
<h2>Downloading the NuGet Package</h2>
<p>Open Visual Studio and choose Mobile App (Xamarin.Forms). In order to use Google Maps, we have to integrate the corresponding NuGet package. Instead of the official version &#8220;Xamarin.Forms.Maps&#8221; by Microsoft, we use &#8220;Xamarin.Forms.GoogleMaps&#8221; by amay077. Please remember to install the NuGet package for each project. The &#8220;Xamarin.Forms.GoogleMaps&#8221; NuGet package by amay077 contains all functions of the official package and some additional ones. Among other things, you can easily replace the markers on the map with your own pictures.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-504 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_NuGet_Paket.jpg" alt="Xamarin Visual Studio Google Maps NuGet Package Nerd Corner" width="1599" height="847" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_NuGet_Paket.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_NuGet_Paket-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_NuGet_Paket-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_NuGet_Paket-768x407.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_NuGet_Paket-1536x814.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>All possible functions of the &#8220;Xamarin.Forms.GoogleMaps&#8221; NuGet package by amay077, to integrate Google Maps in an app, are described on GitHub: <a href="https://github.com/amay077/Xamarin.Forms.GoogleMaps">https://github.com/amay077/Xamarin.Forms.GoogleMaps</a></p>
<h2>XAML code for the Google Map integration</h2>
<p>Since the NuGet package is already installed, Google Maps can now be added to the XAML page. Open &#8220;MainPage.xaml&#8221; and add:</p>
<pre>xmlns: gmaps = "clr-namespace: Xamarin.Forms.GoogleMaps; assembly = Xamarin.Forms.GoogleMaps"</pre>
<p>Then we need the following XAML code to display the map:</p>
<pre><code>
    &lt;Grid&gt;
        &lt;gmaps:Map x:Name="MyMap" MapType="Street" HasZoomEnabled="True" MyLocationEnabled="True" &gt;
            &lt;gmaps:Map.ItemTemplate&gt;
                &lt;DataTemplate&gt;
                    &lt;gmaps:Pin Icon="{Binding PinIcon}" Position="{Binding Position}"
                              Label="{Binding PinLabel}" /&gt;
                &lt;/DataTemplate&gt;
            &lt;/gmaps:Map.ItemTemplate&gt;
        &lt;/gmaps:Map&gt;
    &lt;/Grid&gt;
</code></pre>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-505 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainPage.jpg" alt="Visual Studio Xamarin Forms Google Maps integration Nerd Corner" width="1599" height="847" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainPage.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainPage-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainPage-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainPage-768x407.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainPage-1536x814.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<h2>Get the Google API Key to integrate Google Maps in an app</h2>
<p>Although we have the XAML code to integrate Google Maps in an app, an API key is required. Otherwise we won&#8217;t see anything. Obtaining the API key from Google is easy and quick.<br />
Simply request the API key here: <a href="https://developers.google.com/maps/documentation/embed/get-api-key">https://developers.google.com/maps/documentation/embed/get-api-key </a></p>
<p><span style="font-size: 1.125rem;">Please note that the keys for iOS and Android are different.</span></p>
<h2>Initialize Google Maps for Android</h2>
<p>These are the final steps to display Google Maps in Android. Open the &#8220;MainActivity.cs&#8221; and add the following line in the &#8220;OnCreate ()&#8221; function:</p>
<pre>Xamarin.FormsGoogleMaps.Init (this, savedInstanceState);</pre>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-506 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainActivity.jpg" alt="Visual Studio Xamarin Integrate Google Maps Line for main activity Nerd Corner" width="1599" height="847" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainActivity.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainActivity-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainActivity-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainActivity-768x407.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_MainActivity-1536x814.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>Next, go to <span style="font-size: 1.125rem;">&#8220;Properties&#8221; and </span><span style="font-size: 1.125rem;">select &#8220;AndroidManifest.xml&#8221;. We have to insert here the Google API key and grant the rights for GPS.</span></p>
<p>The is the place where you have to put the line with the meta-data for the Google Maps API Key:</p>
<pre>&lt;application android: label "Name of your app"&gt;Add here the meta-data&lt;/application&gt;</pre>
<p>This is the line with the meta-data for the Google Maps API Key:</p>
<pre>&lt;meta-data android: name = "com.google.android.maps.v2.API_KEY" android: value = "AddYourAndroidAPIKeyHere" /&gt;</pre>
<p>Then the rights for the GPS have to be granted:</p>
<pre>&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
&lt;uses-feature android:name="android.hardware.location.gps" /&gt;
&lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
&lt;uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /&gt;
&lt;uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /&gt;
&lt;uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" /&gt;
&lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
&lt;uses-permission android:name="android.permission.INTERNET" /&gt;</pre>
<p>Afterwards the <span style="font-size: 1.125rem;">&#8220;AndroidManifest.xml&#8221; looks like the screenshot here:</span></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-493 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_AndroidManifest.jpg" alt="Screenshot AndroidManifest for Google Maps API Key" width="1599" height="847" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_AndroidManifest.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_AndroidManifest-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_AndroidManifest-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_AndroidManifest-768x407.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_AndroidManifest-1536x814.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<h2>Initialize Google Maps for iOS</h2>
<p>The initialization is easier for iOS. You just have to open the &#8220;AppDelegate.cs&#8221; and add the following line:</p>
<pre>Xamarin.FormsGoogleMaps.Init ("AddYouriOSAPIKeyHere");</pre>
<h2>Start the app</h2>
<p>The app is now ready to go. Press compile in Visual Studio, then it looks like this:<br />
<img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-496" data-zoom-image="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_standard.jpg" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_standard-512x1024.jpg" alt="Screenshot Google Maps in App Nerd Corner" width="310" height="620" /><br />
It is normal that the app chooses Rome as starting point. The next post shows how you can implement the starting point of the Google Maps app.</p>
<p>Sometimes it happens that the app does not automatically ask for the required rights and therefore it closes immediately after launching. This can be avoided by simply allowing GPS access in the settings or implementing a command to ask for the required rights.</p>
<h2>Download files</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/549/?tmstv=1755868896" rel="nofollow" id="download-link-549" data-redirect="false" >
	Source Code Demo Google Maps App</a>
</li>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/542/?tmstv=1755868896" rel="nofollow" id="download-link-542" data-redirect="false" >
	ActivityMain.cs AndroidManifest.xml MainPage.xaml MainPage.xaml.cs</a>
</li>
</ul>
<p>Please don&#8217;t forget to insert your Google Maps API Key in the source code.</p>
<p>The post <a href="https://nerd-corner.com/how-to-integrate-google-maps-in-an-app-with-xamarin/">How to integrate Google Maps in an App with Xamarin</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/how-to-integrate-google-maps-in-an-app-with-xamarin/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
		<item>
		<title>How to program a web scraper in C#</title>
		<link>https://nerd-corner.com/how-to-program-a-web-scraper-in-c/</link>
					<comments>https://nerd-corner.com/how-to-program-a-web-scraper-in-c/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Wed, 08 Apr 2020 00:05:01 +0000</pubDate>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Web Scraper]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=392</guid>

					<description><![CDATA[<p>A web scraper is used to automatically retrieve data from websites. This data can then be utilized for various purposes. In many cases the data &#8230; </p>
<p>The post <a href="https://nerd-corner.com/how-to-program-a-web-scraper-in-c/">How to program a web scraper in C#</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A web scraper is used to automatically retrieve data from websites. This data can then be utilized for various purposes. In many cases the data is used for apps. We describe how to build a web scraper in C#. You can find the source code of this Demo web scraper at the end of the post.</p>
<p>What is <a href="https://en.wikipedia.org/wiki/Web_scraping">the difference between</a> web scrapers and web crawlers? A web scraper pulls certain information from a website. Crawlers, such as Google Crawlers, search the internet and follow every link they can find to create databases with the sub-pages of websites.  Then they also scrape for certain information.</p>
<h2>List of components</h2>
<ul>
<li>Vistual studio (free)</li>
<li>Webbrowser (Chrome or Brave)</li>
</ul>
<h2>Importing the HTML page source</h2>
<p>At first, open Visual Studio, click on Create new project and select &#8220;Console app (.NET Core)&#8221;. This is the easiest way to demonstrate how a web scraper works. Next, we need a website from which we want to pull information. This website will be our article about programming an Android application to control an Arduino: <a href="https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/">https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/</a>.</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-482 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-webseite-1.jpg" alt="Screenshot website for web scraper Nerd Corner" width="1599" height="848" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-webseite-1.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-webseite-1-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-webseite-1-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-webseite-1-768x408.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot-webseite-1-1536x815.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>Every website is an HTML document. We load this HTML page source into our .NET application and automatically search for information that interests us.</p>
<p>In Visual Studio click on &#8220;Manage NuGet Packets&#8221; and add the HtmlAgilityPack. Define the main function as &#8220;async&#8221; and a variable &#8220;url&#8221; that contains the link to the website. Then add &#8220;System.Net.Http;&#8221; as using directive and create a new HttpClient &#8220;var httpClient = new HttpClient ();&#8221;. Now we can access the HTML data of the website: &#8220;var html = await httpClient.GetStringAsync (url);&#8221; and store it in a variable which we define as HTML document: &#8220;var doc = new HtmlDocument (); doc.LoadHtml (html);&#8221;.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-484 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Laden-der-HTML-Seite-1.jpg" alt="Screenshot web scraper load html data Nerd Corner" width="1599" height="848" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Laden-der-HTML-Seite-1.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Laden-der-HTML-Seite-1-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Laden-der-HTML-Seite-1-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Laden-der-HTML-Seite-1-768x408.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_Laden-der-HTML-Seite-1-1536x815.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>&nbsp;</p>
<pre><code>
using HtmlAgilityPack;
using System;
using System.Net.Http;

namespace DemoScraper
{
    class Program
    {
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            //choose your website
            var url = "https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/";

            //get the html page source 
            var httpClient = new HttpClient();
            var html = await httpClient.GetStringAsync(url);

            //store the html of the page in a variable
            var doc = new HtmlDocument();
            doc.LoadHtml(html);
        }
    }
}
</code></pre>
<h2>Retrieve data from the website</h2>
<p>In fact, the major part has already been done. The source code of the page is loaded into a variable and can now be searched for interesting data.<br />
For example, to pull the title of the article, open the browser, right-click on the post title and then select &#8220;Inspect&#8221;. Now a console opens with the title &#8220;Elements&#8221; and you are automatically at the position of the title in the HTML code of the website.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-485 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/screenshot_chrome_elements_konsole_header-1.jpg" alt="inspect website for web scraping Nerd Corner" width="1599" height="849" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/screenshot_chrome_elements_konsole_header-1.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/screenshot_chrome_elements_konsole_header-1-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/screenshot_chrome_elements_konsole_header-1-1024x544.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/screenshot_chrome_elements_konsole_header-1-768x408.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/screenshot_chrome_elements_konsole_header-1-1536x816.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>&nbsp;</p>
<p>If you take a closer look at the HTML page code, you can see that it is the only &lt;h1&gt; &lt;/h1&gt; attribute. So our scraper can easily search in the &#8220;doc&#8221; variable for &#8220;h1&#8221; and output the text: &#8220;doc.DocumentNode.Descendants (&#8221; h1 &#8220;). FirstOrDefault (). InnerText;&#8221;. &#8220;Console.WriteLine&#8221; is responsible for the output.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-486 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_ausgabe_h1_konsole-1.jpg" alt="Screenshot title web scraper nerd corner" width="1599" height="848" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_ausgabe_h1_konsole-1.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_ausgabe_h1_konsole-1-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_ausgabe_h1_konsole-1-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_ausgabe_h1_konsole-1-768x408.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_ausgabe_h1_konsole-1-1536x815.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>&nbsp;</p>
<h2>Different methods for a web scraper in C#</h2>
<p>We can do the same to scrape subheadings. The console in the browser shows us the attribute &#8220;h2&#8221; here. Since there are several subheadings, we need a list element. So the command is:</p>
<pre><code>//to display the subheaders //Need a list, because there a multiple subheaders
            var subheaders= doc.DocumentNode.Descendants("h2").ToList(); 

            //to display each element in the list
            foreach (var element in subheaders)
            {
                Console.WriteLine("Subheaders: " + element.InnerText);
            }
</code></pre>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-487 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_display-List-of-subheaders-1.jpg" alt="web scraper nerd corner" width="1599" height="848" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_display-List-of-subheaders-1.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_display-List-of-subheaders-1-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_display-List-of-subheaders-1-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_display-List-of-subheaders-1-768x408.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_display-List-of-subheaders-1-1536x815.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>For example, to pull the list of components from the website, we have to search in the HTML code of the page for &lt;ul&gt; &lt;/ul&gt;. By the way, &#8220;ul&#8221; stands for &#8220;unordered list&#8221;. We have the &#8220;ul&#8221; tag several times on the website. 10 times in total. For example, at the end of the article in the section &#8220;Download Files&#8221; is also an &#8220;unordered list&#8221;. W<span style="font-size: 1.125rem;">e only look at the 8th entry of the components variable t</span><span style="font-size: 1.125rem;">o get the component list and not the other &#8220;ul&#8221; lists:</span></p>
<pre><code>//This writes 10 "ul" elements in the list. 
//Our list of components is number 8 in the list
            var components = doc.DocumentNode.Descendants("ul").ToList();
            Console.WriteLine("List items: " + components[8].InnerText);</code></pre>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-488 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_item_list-1.jpg" alt="Web Scraper nerd Corner" width="1599" height="849" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_item_list-1.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_item_list-1-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_item_list-1-1024x544.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_item_list-1-768x408.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_item_list-1-1536x816.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>If you want to scrape the download files, you can simply look at the 9th entry:</p>
<pre><code>//This writes 10 "ul" elements in the list. 
//The Download Files are number 9 in the list
            var components = doc.DocumentNode.Descendants("ul").ToList();
            Console.WriteLine("Download Files: " + components[9].InnerText);</code></pre>
<p>However, this method is not very robust. If a little thing on the website changes, like for example one unsorted list will be deleted, it is possible that the scraper no longer works correctly. The &#8220;Download Files&#8221; can also be displayed in a different way:</p>
<pre><code>
//The Download Files are links and the class is called download-links, 
            //so we search for  with this attributes
            var downloadFiles = doc.DocumentNode.Descendants("a")
                .Where(node=&gt;node.GetAttributeValue("class","").Equals("download-link")).ToList();
            
            //to display each listelement
            foreach(var element in downloadFiles)
            {
                //the name of the file
                Console.WriteLine(element.InnerText.Trim('\n','\t'));

                //the downloadlink of the file
                Console.WriteLine(element.GetAttributeValue("href","").Trim('\n','\t'));
            }
</code></pre>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-489" src="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_items_downloadfile_namelink-1.jpg" alt="Web Scraper in c# nerd Corner" width="1599" height="848" srcset="https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_items_downloadfile_namelink-1.jpg 1600w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_items_downloadfile_namelink-1-300x159.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_items_downloadfile_namelink-1-1024x543.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_items_downloadfile_namelink-1-768x408.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/04/Screenshot_items_downloadfile_namelink-1-1536x815.jpg 1536w" sizes="auto, (max-width: 1599px) 100vw, 1599px" /></p>
<p>If we browse the &#8220;Element Console&#8221; for &lt;a&gt; &lt;/a&gt;, we get all elements with web links. We also specify the link by looking for these which belong to the &#8220;download-link&#8221; class. So we get exactly the entries that we wanted. The name of the download link can be displayed with &#8220;InnerText&#8221; and the download link itself can be obtained with &#8220;GetAttributeValue (&#8221; href &#8220;,&#8221; &#8220;)&#8221;. &#8220;Trim&#8221; removes unnecessary blank lines and spaces.</p>
<h2>Useful tips for a web scraper in C#!</h2>
<p>The &#8220;Elements Console&#8221; does not always show the actual page source text! Sometimes, as for example with Google Maps, additional Java scripts are loaded so that the actual HTML page source text does not correspond to the &#8220;Elements Console&#8221;. To check, simply right-click and click on &#8220;View page source&#8221;. The page source html is important. We read this into our .NET application and we search here for the desired information.</p>
<p>The outer shape of the scraped text is often not ideal. There are many spaces, empty lines, shifts or unwanted characters. But you can easily adjust the outer shape:</p>
<pre><code>
char[] charsToTrim = { '*', ' ', '\'','\n','\t', '\r', };
Console.WriteLine(element.InnerText.Trim(charsToTrim));
</code></pre>
<h2>Download File</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/409/?tmstv=1755868896" rel="nofollow" id="download-link-409" data-redirect="false" >
	Demo Web Scraper</a>
</li>
</ul>
<p>The post <a href="https://nerd-corner.com/how-to-program-a-web-scraper-in-c/">How to program a web scraper in C#</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/how-to-program-a-web-scraper-in-c/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
