Sonntag, 30. Dezember 2007

Visual Studio Express Editions Installation

Getting the express edition

Fist go to http://www.microsoft.com/express/ and then navigate to Download.

download page in Souvergin

(the download page in Souvergin which is a browser I am working on) 

From this point on you have as in the past two way of installing VS Express Editions.

Web Install

In this case you select the version and language of your choose (At that time only English and Japanese are available). Then  your Browser will download a small installer file - e. g. 2,5 MB for Visual Basic Express Edition. The real Application Download is made during setup. You can use this way if you have a fast Internet Connection or do not need to install Visual Studio a few times - otherwise I would prefer the Offline installation.

Offline Install

By using the offline install you only select the language and then your Browser will download DVD Image with about 900 MB. This Version includes the  whole Express Suite. Containing all Express Editions. After Download you will have to burn the iso image on a DVD or mount it into a virtual DVD drive.

Installation

As in past the Visual Studio installer needs a long time for installing everything. Using WebInstall makes the setup even slower, because all files are downloaded while Setup. The setup time depend also on what you have already installed on your Computer. So if .NET FX 3.5, the SDK's MSDN and SQL Server is installed - maybe because if you have already another Express Edition on your PC, the Setup runs much faster.

image 

Looking into the image: They set the wrong image transparent colour for the globe. Even really big companies make such little nasty mistakes - that happens not only to me -)

 

So next post of our VS 2008 Express Edition series is about Visual Basic 2008 Express Edition.

Visual Studio 2008 - Express Editions

In following entries we will focus on the new VS Express Editions and compare them to the predecessors. First we will start with Visual Basic's 2008 Edition followed by C#'s and C++'s and maybe we will also include Visual Web Developer (do not take that for granted, because this blog focuses on Windows Client Developement). Since J# is not a member of the Visual Studio 2008 family anymore we can not review anything about J# and VS 2008.

Sonntag, 16. Dezember 2007

Sending e-mails with System.Net

Many programs call the default e-mail program for sending Mails. But what is if a user use an Webmail Account instead of Outlook, Live Mail, Windows Mail, Thunderbird or all the other mail clients? In many cases e-mail provider support sending e-mails via SMTP (the protocol also mostly is used by real mail clients). 

Know I will show you how to send a mail via .Net and how to attach files to your mails.

Every sting in the code samples could be replaced by a parameter added to the Send method.

Imports System.Net.Mail
Public Class SendMail
Public Shared Sub Send()
Dim message As New MailMessage("sender@servername", "from@servername", "Subject", "MessageText")

Dim emailClient As New SmtpClient("servername")
emailClient.Send(message)
End Sub
End
Class


That's the easiest way. This way does NOT work in most cases. As you see: No account name and account password was used. Which e-mail allows this? No serious one ;) 



In many cases it is useful to define a port which your SmtpClient uses. Normally it is Port 25.



So we are going to extend the code.



Imports System.Net.Mail
Public Class SendMail
Public Shared Sub Send()
Dim message As New MailMessage("sender@servername", "from@servername", "Subject", "MessageText")
message.IsBodyHtml = False

Dim emailClient As New SmtpClient("servername", 25)

emailClient.DeliveryMethod = SmtpDeliveryMethod.Network
emailClient.Credentials = New System.Net.NetworkCredential("username", "password")
emailClient.Send(message)
End Sub
End
Class



Additionally I set message.IsBodyHtml to false, because we are sending just plain text and emailClient's DelivertyMethod was set to Network.



If you replaced every sting in the sample with real data by doing this in the method itself or by using method parameter, now the code should work and you are able to send a mail.



Next step: attachments.



Imports System.Net.Mail
Public Class SendMail
Public Shared Sub Send()
Dim message As New MailMessage("sender@servername", "from@servername", "Subject", "MessageText")
message.IsBodyHtml = False

Dim emailClient As New SmtpClient("servername", 25)

emailClient.DeliveryMethod = SmtpDeliveryMethod.Network
emailClient.Credentials = New System.Net.NetworkCredential("username", "password")

Dim Attachment As New Attachment("Path to your file")
message.Attachments.Add(Attachment)

emailClient.Send(message)

End Sub
End
Class


As you see I just created an System.Net.Mail.Attachment object which constructor uses a parameter for the file I want to send. Then the Attachment is Added to the attachment Collection of our message.

Freitag, 14. Dezember 2007

Clever Controls - Loading URLs instead of local paths

Did you know, that many .net Controls are able to open files over the internet? The word does not end in your local file systen and even not in your LAN - no you can open files over the Internet. Oney way to do this is surely to use System.Net.WebClient and save the Image local another way is just to give the control the URL.

For an example we are using the picturebox and let it display google germany's Logo.

So we create a Windows Forms project, a Form and put there a picture box in.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CleverPictureBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.pictureBox1.ImageLocation = "http://www.google.de/intl/de_de/images/logo.gif"; //Points to google germany's logo
}
}
}


All I did was putting the URL into the Images Location. The Control did the rest for me. 



GoogleII



You can do this with many other Controls but there is still one problem remaining, the Control can not use the file as fast as it would be local stored. So it takes longer to download it temporary and opens it as open a file on your drive, which is not any surprise. So in most cases the System.Net.WebClient should be used to download the files bevore the shuld be displayed - but in some cases this open an URL instead a local path metod could be useful.

How to make Screenshots using System.Drawing

The normal unmanaged GDI has a "PrintWindow" Method, where a Screenshot can be taken from a Window Handle. With .net you can also make Screenshots. The folowing example shows how to make a screenshot from a specialised area of the screen.

Imports System
Imports System.Drawing
Public Class Screenshot'Version 1.1.2 for Souvergin Sequaia (NX Codebase)
Public Shared Function Shot(ByVal rectangle As System.Drawing.Rectangle, ByVal Location As Point) As System.Drawing.Bitmap
Dim memoryImage As System.Drawing.Bitmap = New System.Drawing.Bitmap(rectangle.Width, rectangle.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)

Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
myGraphics.CopyFromScreen(Location.X, Location.Y, 0, 0, rectangle.Size, System.Drawing.CopyPixelOperation.SourceCopy)

If Not memoryGraphics Is Nothing Then
memoryGraphics.Dispose()
End If


        Return memoryImage 

End Function
End
Class



The function needs two parameters for taking the screenshot. One the one hand a rectangle which is the size of the screenshot and a Point  - location - which indicates where the staring point is for taking the screenshot.



In the function a Bitmap is first a bitmap with the by the parameter rectangle specified size is created. After that the Graphics memoryGraphics is declared and the screnshot is taken by the CopyFromScreen Method. Location.X and Location.Y are the starting coordinates for the screenshot, the following two zeros are made that 0,0 is the start point in the destination rectangle on the bitmap. Rectangle.Size specifies the size of the screenshot.



At the end the Screenshot is returned.

How to read data with System.Xml.XmlTextReader

theSince in the last post an example of System.Xml.XmlTextWriter was used to write an XML-document this article will show how to read an XML-document.

Private Shared Sub LoadXMLfile(ByVal Path string)
If My.Computer.FileSystem.FileExists(Path) Then
Dim rdrXML As New System.Xml.XmlTextReader(Path) //Consturctor with XML file's path
Try
rdrXML.MoveToContent()

Dim ElementName As String = ""
Dim NextItem As Boolean = True
Dim objListViewItem As Favoritenobjekt = Nothing
Do While rdrXML.Read
If NextItem Then
objListViewItem = New Favoritenobjekt
NextItem = False
End If
Select Case rdrXML.NodeType
Case System.Xml.XmlNodeType.Element
ElementName = rdrXML.Name
Case System.Xml.XmlNodeType.Text
If ElementName = "Name" Then
objListViewItem.Text = rdrXML.Value
End If
If ElementName = "Kategorie" Then
objListViewItem.Kategorie = rdrXML.Value
End If
If ElementName = "URL" Then
objListViewItem.URL = rdrXML.Value
Favoriten_Liste.Add(objListViewItem)
NextItem = True
End If
End Select
Loop
rdrXML.Close()
rdrXML = Nothing
Catch ex As System.Exception
MsgBox("Error. Xmlfile could not be loaded", MsgBoxStyle.Critical)
End Try
End If
End Sub




What is important in the code?



The XMLTextReader is constucted with the path to the file which you are trying to read. rsrXMl.MoveToContent Points the Reader to the Data.  Since you do not know how much information is in the file you have to use a while loop. Important in this way of reading the data is that we are first reading an node then, we check if it is an Element or Text. The Elementname is stored in 'Elementname' which is needed to identify the element the Text (case 2) belongs to.