.NET Programming

132K

Solutions

38K

Contributors

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

Share tech news, updates, or what's on your mind.

Sign up to Post

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
2
How to Create Failover DNS Record Sets in Route 53
How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
4
 
LVL 3

Expert Comment

by:alohadin
Comment Utility
This has been bookmarked!
Great stuff Shaun.
Thanks a lot.
1
 
LVL 8

Expert Comment

by:Senior IT System Engineer
Comment Utility
thanks for sharing such a great article Shaun :-) !
0
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a few months or a few weeks to get market trend inform.
0
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still read this article from here.
 
Creating a DLL to be hosted in SQL Server let you run code directly in the database. You may think of it as a Stored Procedure written in VB or C#. it might be helpful to prevent doing large processing on the client after having transited a lot of data on the network wire.
 
Lately, I was reviewing training material on that topic to see if it was still accurate and found out that many things have changed since then. We are now using Visual Studio 2013 (or 2015 in CTP) and SQL Server 2014.


Downloadable code


This month code is available in both VB and C#. The solution has been created using Visual Studio 2105 CTP 5 but would also work the same way if you are using VS 2013.
 

You will also need Microsoft SQL Server. I have used SQL Server 2014 but should also work with SQL Server 2012.

You will also need to install Microsoft SQL Server Data Tools (aka SSDT) which are tools added to Visual Studio to provide a better interaction between the 2 products. If you don’t already have it, you can get it from https://msdn.microsoft.com/en-us/data/hh297027. SSDT is also installable right from within Visual Studio. The code can be downloaded from here.


Simple method

1
 
LVL 66

Expert Comment

by:Jim Horn
Comment Utility
We have a checker and can tell, rule is minimum 85% original content.  Two exceptions are now allowed
  • Vendor accounts can do whatever the heck they want.
  • Previously published by the author under their own name, as long as we check the NoIndex checkbox so search engines can't search to it.

That and Netminder and Todd Lherrou were shown the door, I'm apparently the only article editor left standing, and I like this article.
0
 
LVL 70

Author Comment

by:Éric Moreau
Comment Utility
Thanks Jim. Don't give up.
0
DelegatesInC#
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that understanding with Experts-Exchange users.
2
 
LVL 11

Author Comment

by:ROMA CHAUHAN
Comment Utility
Hi St. Jimbo,

Thanks for your valuable inputs.

As this is my very first article so I was not aware of all these points. I have submitted my article with the specified modifications.  Please review it again.


Thanks,
Roma
0
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
3
 
LVL 66

Expert Comment

by:Jim Horn
Comment Utility
Very well written, and I can see how this can be very useful.  Voted Yes.
0
 
LVL 110

Expert Comment

by:Ray Paseur
Comment Utility
0
Donut Hole Caching is the inverse of Donut cache. As the previous statement, the Donut Caching is used to cachea maximum portion of the view/page, but Donut Hole Caching is used to cache only small portion of the view/page.
0
Donut caching used to cache an entire web page except for one or more small portions of the page. In other words, suppose we want to cache a maximum portion of the view except the minimum portion then we can finalize to use DonutCache.
0
 
LVL 3

Author Comment

by:S.Thiyagu Thiyagu
Comment Utility
Hi ericpete,

Thanks For the correction.. I will correct all the thing which you mention here.
0
Web Service Task and XML Task
My client sends a request to me that they want me to load data, which will be returned by Web Service APIs, and do some transformation before importing to database. In this article, I will provide an approach to load data with Web Service Task and XML Source components in SSIS.
4
 
LVL 66

Expert Comment

by:Jim Horn
Comment Utility
Very well illustrated, and reads real well considering how difficult the subject is.  Voting Yes.
0
How to load multiple sheets
My client sends data in an Excel file to me to load them into Staging database. The file contains many sheets that they have same structure. In this article, I would like to share the simple way to load data of multiple sheets by using SSIS.
2
 
LVL 66

Expert Comment

by:Jim Horn
Comment Utility
Outstanding article on a common Excel and SSIS issue.  Voted Yes.
1
 

Expert Comment

by:Mahzar Ahsan
Comment Utility
Great article. Solved my issue.
0
Revamp Your Training Process
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Entity Framework 6
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
2
Exception Handling is in the core of any application that is able to dignify its name.
In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
2
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to do amazing, modern things with bits!
27
 
LVL 35

Author Comment

by:gr8gonzo
Comment Utility
@philkryder - The impact is going to be different depending on the application. For example, let's say that you do have this situation where you're dealing with 20 million 15-byte strings (roughly 286 megabytes).

If you're dealing with a database, then typically you're in a client/server setup, so the client needs the data locally in order to do any viewing or processing (this can be expanded also to a scenario where you've got DB Server -> Web Server -> End User, and data has to be transferred twice - and that's just basic setups).

Typically, the data's going to be transmitted over a TCP/IP network connection, so you're also adding about 8 megs of TCP overhead for 300,000,000 bytes (versus 2 megabytes for 80,000,000 bytes). You also have overhead of the structure containing/defining the data, plus any extra identifying data, but we'll set that aside for now.

So let's say that the database server has all the resources it needs to send all the data across to the client. On a LAN, it might not take too long either way, but you'll still notice a significant difference between transferring 78-ish megs vs 294-ish megs.

If you're dealing with a situation where you transfer that over a broadband connection of some kind, the difference will be even larger.

So the majority of the time, your "extra time" is going to be found in the data transfer, since that's often the slowest point. For the sake of having some example numbers, let's say that we're transferring over a 60Mbps connection, so we're looking at anywhere from 30 seconds - 45 seconds to download a roughly-300 meg payload, and 10-15 seconds to download a roughly 80-meg payload.

We'll say that we can save about 20-30 seconds in transfer time.

Now let's say the client app finally has the data in memory. It probably needs to store it somewhere, so there's some kind of structure involved, which also means an extra % of overhead storage in memory. Let's say you have a C# app using a DataTable structure. A string column in a DataTable takes up a LOT more memory per row than a long column. I don't have hard numbers in front of me, but I did have a project once where I hadn't defined my column type and I was accidentally storing small integers as a string. When I fixed the problem with a byte type definition on the field, memory usage dropped by several hundred megabytes.

So now we've got a client app with the data in memory. What's the next step?

If we're displaying the data on-screen, then chances are that you're probably only converting a handful of records at a time - maybe 200 at most.  The time it takes to convert 200 longs into string is around 0.001 seconds each time (just a rough test on my end).

But let's say you want to convert those 20 million numbers into 20 million entries all at once to be written to a file. Let's say that looping through 20 million records in memory takes a full 3 seconds, with absolutely no processing at all, so it wouldn't matter if the numbers were already converted or not - 3 seconds is the starting baseline. Your question is then - how much ADDITIONAL time would it take to convert 20 million numbers? A rough test on my machine shows about 40 seconds, and of course, that's going to depend on processor power. Many machines might be even slower.

So now we have some example numbers.
You have about 20-30 seconds of savings on the transfer side. If you were to turn around and convert all of those to strings immediately and write them to a file, then you're probably looking at a speed LOSS of roughly 10 seconds. Of course, this also doesn't take anything else into consideration (the value of bandwidth pipes / network saturation / memory / likelihood of this scenario / scalability across multiple clients / etc).

For displaying the data on-screen, you have about 20-30 seconds of savings on the transfer side, and virtually no time spent on conversion since you're not doing them all at once. The client's not going to notice a split-second of extra time every time they move to a new page of results.

Either way, there is a LOT of extra value in more efficient storage. There will always be some scenarios where it doesn't make sense to compact everything, but that's where being a good programmer comes into the picture and understanding the business case and how it translates into data flows and the value of each resource involved, and how that multiplies with concurrent load.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
Comment Utility
Excellent article!  The only thing I would have included would be a small section on Endianness (Big Endian vs. Little Endian).
0
I have seen a presentation lately about unit testing. One of the aspect covered by the presentation was the use of fluent interface to ease the wording of the tests (and ease the reading at the same time).

Is that limited to unit testing? Of course not. What a great way to provide an API to many of our classes.

This article will show you how to create fluent interface in your own classes to use from anywhere you are using your classes.

What it is


Consider this first example:

Dim s As String = "Eric Moreau"
s = s.Trim()
s = s.ToUpper()
s = s.Replace("R", "z")

Open in new window


The readability of these statements is arguable at best and it is not very efficient (knowing that strings are immutable). It is also a bit too long to write. We don’t want to always break line and assign again.

Another way of writing the same as above, is this simple line:

Dim s As String = "Eric Moreau".Trim().ToUpper().Replace("R", "z")

Open in new window


This is an example of a fluent interface that you have surely used for years. The result of the first string is passed to the Trim method which is in turn passed to the ToUpper method to finally be passed to the Replace method before being returned to the variable.

If you have used LINQ, Entity Framework, NHibernate, most mocking tools, and many others, you have already used fluent interfaces maybe without explicitly knowing you were using them.

Fluent interface is normally implemented by using method cascading to relay the instruction context of a subsequent call (source: Wikipedia
3
 
LVL 70

Author Comment

by:Éric Moreau
Comment Utility
Done.
0
If your Visual Studio Setup and Deployment project includes a prerequisite for the Microsoft Visual C++ 2010 Redistributable and the setup.exe fails with the following error:

A newer version of Microsoft Visual C++ 2010 Redistributable has been detected on the machine.

Try this solution which worked for me:

Note that at the time of this writing c++ 2010 Redistributable is at SP1 ( v10.0.40219 )

The environment in which this problem was manifest is Visual Studio 2010 SP1 & SDK v7.0A

VB 2010 solution comprised of
                - Windows Forms Application Project
                - Setup and Deployment Project ( x86 target & Prerequisites )
                - Setup and Deployment Project ( x64 target & Prerequisites )

One of my prerequisites is for the Microsoft Visual C++ 2010  x## Redistributable

The vcredist_x## packages in my
    C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages
folders were deploying 10.0.30319 and the prerequisite install would fail  if c++ Redistributable 10.0.40219 was already installed ( TeamViewer installs 10.0.40219 for example ).

To resolve this issue three changes were required for each the x64 and the x86

    1) Download the vcredist_x##.exe for 10.0.40219 overwriting the existing
           http://go.microsoft.com/fwlink/?LinkID=210622    for the x64
           http://go.microsoft.com/fwlink/?LinkID=210621    for the x86

    2) Change the…
0

Introduction


Using Linq and Entity Framework may result in very slow operations.
Our 1st reflection might be: "To bad EF is too slow and can't be used in production applications."
But, we may wish to consider rechecking our code…

Background 

In one of my application, users had experienced a very long operation (some times more than 1 minute), which is unacceptable for a production application.
I had created a Bug for that, and start tracking the issue. One very useful tool I use to track long queries through EF is SQL Server Profiler. This can help to see how many records are sent by SQL Server to the application, and check if it makes sense with the results expected.
I use LinqPad application, too, to execute my Linq query easily.

Initial version of the query


After tracking my code I isolated the query that was taking a lot of time, and copy-and-paste it into LinqPad : 

Dim result As Boolean

result = (From w In packEntity.SenderPacks Select w.Sales.Any).Any

result.dump

Open in new window


Execution time :  24.512s

As we can see 24 sec just to rest a Boolean, it certainly to long.
Let's see the query and execution plan:

-- Region Parameters
DECLARE @EntityKeyValue1 BigInt = 1000
-- EndRegion
SELECT 
[Extent1].[PKID] AS [PKID], 
[Extent1].[LaboratoireCode] AS [LaboratoireCode], 
[Extent1].[CentraleCode] AS [CentraleCode], 
[Extent1].[CentraleProduit] AS [CentraleProduit], 
[Extent1].[ProduitProdCode] AS 

Open in new window

1
dog-poodle-snow-sweater-pe<wbr />t-413141
Ever wonder how to "do" object oriented programming (OOP)?
4
 
LVL 15

Author Comment

by:David L. Hansen
Comment Utility
Quite right Doug.  Thanks for your thoughts!
0
 
LVL 15

Author Comment

by:David L. Hansen
Comment Utility
Thanks.
0

Introduction

We purchased a custom-modified C#/Silverlight 5 application from a third party. This program was designed to allow processing of maintenance work orders on remote Windows 8 Pro machines when in either a connected (WiFi or 3G) or disconnected state. Silverlight application storage is used to store all of the work order, parts, history, comments, and labor data downloaded from the mobile server.

The source code for the application is stored in a GIT repository on Bitbucket.org, so modifications can be made by either the third party or our programmers. With the explosive growth of software development in the Cloud, this is becoming an increasingly common situation. With the increased use of Agile programming techniques, new versions or releases are delivered more frequently as well. Add to that the complexity of deploying the software on a regular basis to a variety of hardware and software platforms necessitated by the increased use of mobile devices.   

Because of all of the above, the IT department is frequently required to deploy new and updated software, which in this case proved to be a difficult and uneven process. We eventually got it to work properly through several months of trial and error. By following the techniques in this article others may avoid the costly mistakes and problems we encountered. Cheers.
 

Deployment

The software modification and deployment process is as follows:
1.      Verified (tested and approved on a …
0
Sometimes it is useful to have a class that is a representation of an object.
The object may be an element of a list and the list itself can too.
When I query a db to get the fields of my object, I want to write them into a class.
This is the way I do:

1. Base class for Entity

This step will enable you to better code writing and clarity.
[Serializable]
public class BaseEntity
{
    public BaseEntity() { }
}

Open in new window

I will add later some extension method that will give further help.

2. Base class for Entity List

This class is the list of typed objects
[Serializable]
public class BaseEntityList<TEntity> : List<TEntity>
    where TEntity : BaseEntity
{
    public Int32 VirtualItemCount;

    public BaseEntityList()
    {
    }

    public BaseEntityList(Int32 capacity)
        : base(capacity)
    {
    }

    public BaseEntityList(IEnumerable<TEntity> collection)
        : base(collection)
    {
    }

    public virtual void FromEntityArray(BaseEntity[] entityArray)
    {
        Clear();
        AddRange((TEntity[])entityArray);
    }

    public virtual void FromIEnumerable(IEnumerable<TEntity> entityList)
    {
        Clear();
        AddRange((TEntity[])entityList);
    }
}

Open in new window

Please note that I added different constructors and some methods that can become useful (but maybe you'll never use them).

3. Create the class for your object (Entity)

[Serializable]
public class record : BaseEntity
{

Open in new window

0
Free Tool: ZipGrep
LVL 9
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

A Few Words About LINQ
LINQ is a high level querying lanquage. It was made in order to unify the way a programmer queries different sources, like databases, lists and objects. That is the power of it, as you may change datasource and your LINQ may remain the same producing the same results.
 
As it is a querying lanquage you may find similarities with T-SQL, such as keywords (SELECT, FROM, WHERE), but there are also differences. The major difference is the syntax, but also the simplicity of LINQ when it comes to complex queries.  

Of course LINQ is not always the best choice. For instance LINQ is not good for handling bulk inserts.

Now lets see how LINQ implements various cases of JOIN queries, compared with T-SQL.

Introduction
This article is meant to give a helping hand to people that have dificulties when it comes to joining their LINQ queries.

In all examples we will use two tables names for simplicity TableA and TableB. I am using "tables" as I am fond of SQL, but this article also applies to whatever LINQ applies to.

Below are the the tables we are going to use through this article:

TableATableB
Code samples will be given both in VB and C#.

Before we begin lets have a look at the Class constructors:
C#
    public class TableA
    {
        public string Name { get; set; }
        public string Pet{ get; set; }
    }
    public class TableB
    {
        public string Name { get; set; }
        public string TransportationType { get; set; }
    }

Open in new window


VB

Open in new window

6
 
LVL 49

Expert Comment

by:PortletPaul
Comment Utility
Giannis: fantastic. Thanks for this, very helpful indeed. Well done!
0
 

Expert Comment

by:Nico2011
Comment Utility
Excellent as always!  Thanks very much!
0

Probing Assembly:
Simple Assembly Probing (a .NET assembly without strong name)

Whenever the .NET common language runtime (CLR) tries to locate an assembly, it performs certain steps, including probing. To begin learning this concept, this article will start with an example application that does not use strong-named assemblies. I will discuss strong-named assembly probing in a subsequent next article. Therefore, let's begin with a console application named AssemblyResolutionDemo.
using System;

namespace AssemblyResolutionDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(
                FullName.NonGAC.FullName.GetFullName("John", "Smith")
            );
            Console.WriteLine(
                typeof(FullName.NonGAC.FullName).Assembly.CodeBase
            );
            Console.Read();
        }
    }
}

Open in new window



As the code example reflects, AssemblyResolutionDemo references  a project/assembly named FullName.NonGAC.
using System;

namespace FullName.NonGAC
{
    public class FullName
    {
        public static string GetFullName(string firstName, string lastName)
        {
            return string.Format("{0}, {1}", firstName, lastName);
        }
    }
}

Open in new window


Notice that the GetFullName function returns a formatted string, which we are accessing in the main application. The assembly's codebase outputs the file path of the loaded assembly, making it easier for us to validate the location from where the CLR loads the assembly.

1. The CLR will check the applications’ base directory first.

When the application runs, the CLR checks the bin directory of the application, loading the assembly if it exists.
 Img003
2. If the assembly does not exist in the bin directory, the CLR checks for a subdirectory with the assembly name (e.g., bin\FullName.NonGAC).
0
With the advent of Internet Explorer 9's enhanced SmartScreen Filter (also built into Windows 8, so on Win8 it affects users of other browsers) using Application Reputation, developers who make their software available for download online (particularly trial versions that you're using to try to gain new users with) have ever more reason to think about digitally signing their application and its installation file. By digitally signing your application, you reduce the likelihood that people will be scared off from trying your application because of the ominous warning that your software "is not commonly downloaded and could harm your computer," and the resulting extra hoops they have to jump through to actually run or install your application.

Digitally signing your software's application and installation files helps in five ways:

1) Instead of "unknown publisher," Windows will now report your name as "Verified Publisher" when someone runs the installer.
2) SmartScreen determines the reputation of your software (to decide whether it is "commonly downloaded") based not on the individual build of the installation file, but on all files that use the certificate. This means that if you have multiple applications, or multiple builds (because you're releasing the software with new features, or you have different variants of the application), all of them are summed together for Microsoft to decide the reputation score.
3) Even when your digital certificate is new and …
3
 
LVL 15

Administrative Comment

by:Eric AKA Netminder
Comment Utility
ElrondCT,

Congratulations! Your article has been published.

ericpete
Page Editor
0
 
LVL 51

Expert Comment

by:Mark Wills
Comment Utility
Great Article... Wish every developer would follow suit...
0
This is one of the simple operators yet less used due to clarity over its purpose. Let’s looks at it
1.ANDALSO :

Take an example where we are evaluating the business logic.

 Img1
Output
 
Img2
Case 1: In this case program will execute the IsValidUser function, it returns valid and then execute the HasAccessToUpdateOrders function which is false and everything is ok.

Case 2. Consider  here IsValidUser returns false then logically there is no way  that user might have any Access to update Orders, however the programs still executes the function  HasAccessToUpdateOrders. Logically this should have been avoided, unnecessary execution consuming resources and time.  Hence when we use AND both sides of expression will be executed before considering the final result.

So to avoid this we have short-circuiting, so now the same stuff with ANDALSO. And the output seems to evaluate only the first part since it’s false it doesn’t evaluate the second expression and improves the performance.

Img3
Output:
 
Img4
2. ORELSE:

Taking same example from above but instead of IsUser we consider IsAdmin, so if user is Admin then he should have access to update orders no need to check further.

 Img5
Output:
 
Img6
Case 3: In this case program will execute the IsAdmin function, it returns false and then execute the …
0
This is just a little tutorial on how to create a custom window

1. Create a new project and choose WPF-Application
Screenshot 1
2. Add
AllowsTransparency="True" Background="Transparent" WindowStyle="None"

Open in new window

To the Window Tag.

Your XAML should now look like this
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" AllowsTransparency="True" Background="Transparent" WindowStyle="None">
    <Grid>
        
    </Grid>
</Window>

Open in new window


2. Add a "Border"-tag inside the grid. You can add attributes to it like CornerRadius to make rounded corners.

3. Now we're setting the background. I'll use a linear gradient.
for this you add a "Border.Background"-Tag inside the border and a "LinearGradientBrush"-Tag inside it.

Your XAML should now look like this
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" AllowsTransparency="True" Background="Transparent" WindowStyle="None">
    <Grid>
        <Border CornerRadius="20">
            <Border.Background>
                <LinearGradientBrush>
                    
                </LinearGradientBrush>
            </Border.Background>
        </Border>
    </Grid>
</Window>

Open in new window


4. Now the creative part. Put this inside the LinearGradientBrush tags:
<GradientStop Offset="0" Color="Gray"/>

Open in new window

As you can think offset is the distance from the start point. You can put any value in it. 0 means at the start point, 1 at the end point. And Color is just any color you like

Add a few other options to these tags.
Than you can change the
<LinearGradientBrush>

Open in new window

Tag to
<LinearGradientBrush StartPoint="1,1" EndPoint="0,0">

Open in new window

Play a bit around with the values for StartPoint and EndPoint, until you think it looks good.

My XAML now looks like this

Open in new window

1
When our application needs to send an email, there are two major options. One is to use Outlook, which is what most articles on the web are about - especially on Microsoft-related websites. Naturally, this assumes that Outlook is installed. Fortunately, there's more lightweight way to do it, by using .Net library System.Net.Mail. The following simple code will do the job of sending HTML email which content is stored in the file htmlpage1.htm, part of our project:

 
    Dim f As New StreamReader(My.Application.Info.DirectoryPath & "\htmlpage1.htm")
        Dim HTML As String = f.ReadToEnd()
        f.Close()

' (assuming that the file is in fact a template, at this point we probably will manipulate the text by replacing some placeholders by the current values)

        Dim email As New System.Net.Mail.MailMessage("from-address","to-address")
        email.Subject = "experts-exchange article"
        email.Body = HTML
        email.IsBodyHtml = True

        Dim smtp As New SmtpClient
        smtp.Host = "smtp-server-address"
        smtp.Credentials = CredentialCache.DefaultNetworkCredentials 
        smtp.Send(email)

Open in new window

Things become more complicated when the HTML that we want to send includes an image. The easiest is to specify image source in HTML as a link to the external website hosting the image:

<img src="http://www.experts-exchange.com/images/experts-exchange/experts-exchange-logo.png" />

However, this solution has the following major drawbacks:

1. it assumes that external website is accessible by the user, and that the hosted image is in place. Considering the fact that this email may be stored and looked at years later, this is not a solid assumption.not-found2. Modern email clients will block external image by default, for security reasons. The user more likely than not will see a placeholder, possibly with the option to download the image, which he more likely than not will not do.blocked-by-client3. External content will increase the chance of the email to be blocked by antispam software.detected as spam
0

.NET Programming

132K

Solutions

38K

Contributors

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.