Wednesday, October 25, 2006

File Properties using C#

File Name of your file:

When reviewing or opening a file, to get its name, the FileInfo class is equipped with the Name property. Here is an sample code:


FileInfo oFileInfo = new FileInfo(strFilename);
MessageBox.Show("My File's Name: \"" + oFileInfo.Name + "\"");


Date and Time a File Created

The Operating System takes care to keep track of the date and time of a file was created. To find out what those date and time values are, you can access the File System Information property using.

DateTime dtCreationTime = oFileInfo.CreationTime;
MessageBox.Show("Date and Time File Created: " + dtCreationTime.ToString());

Find your file extension:

When you access a file or when the user opens one, to know the extension of the file, you can access the value of the FileSystemInfo.Extension property.

MessageBox.Show("myFile Extension: " + oFileInfo.Extension);

Find file size using C#:

One of the routine operations the operating system performs consistly for all the file is calculating the size of files it holds.

MessageBox.Show("myFile total Size: " + oFileInfo.Length.ToString());

a

Tuesday, October 24, 2006

Community for .NET Technology

Here is one of the best interactive community for .NET Technology. All .NET technology lovers and programmers come lets add power to your .NET skill.

Click Here To Join The Community

Monday, October 23, 2006

Creating System Tray Applications in Windows Forms .NET 2.0

This simple article explains how to implement the common features and functionalities required for a notification-based application in Windows Forms: starting up a Windows Forms application without showing a Form, using the NotifyIcon, bringing an existing Form to the front of the desktop, and closing the Form on minimize.

Create Icons At Runtime For The System Tray in .NET

This simple way of creating Icons for system tray at runtime using .NET. Here is the code sample for creating the Icon for sytem tray.

String TaskBarLetter;
// Create a graphics instance that draws to a bitmap
Bitmap bitmap = new Bitmap(16, 16);
SolidBrush brush = new SolidBrush(fontDialog1.Color);
Graphics graphics = Graphics.FromImage(bitmap);
// Draw then number to the bitmap using the user selected font
if (i != -1)
TaskBarLetter = i.ToString();
else
TaskBarLetter = "V";
graphics.DrawString(TaskBarLetter, fontDialog1.Font, brush, 0, 0);
// Convert the bitmap into an icon and use it for the system tray icon
IntPtr hIcon = bitmap.GetHicon();
Icon icon = Icon.FromHandle(hIcon);
notifyIcon1.Icon = icon;
//GetHicon creates an unmanaged handle which must be manually destroyed
DestroyIcon(hIcon);


For this application, we’ll need to create a new NotifyIcon, ContextMenuStrip, and a few MenuItems for the ContextMenuStrip. The icon is set, and the NotifyIcon is set to Visible = true. The NotifyIcon.Text property is used in order to display a ToolTip on mouse hover. when you want to get the application out of the System Tray you have to use a Context Menu. First you must associate both the form and the Notify Icon with this context Menu. Just go into the properties for both of those items and set the ContextMenuStrip property to the name of your ContextMenuStrip(in this case contextMenuStrip1).



Download The Sample Sourcecode>>

Monday, October 16, 2006

Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System Beta

Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System Beta (also known as “Visual Studio 2005 Tools for Office Second Edition Beta” or “VSTO 2005 SE Beta”) is an add-on to Microsoft Visual Studio 2005 that enables you to build application-level add-ins for the 2007 Microsoft Office system as well as the Microsoft Office 2003 Editions.

Download VSTO 2005 SE

This contains application level add-in project template for six applications in Office System 2007. One exception is the InfoPath 2007 form project template. If the InfoPath 2003 Toolkit is installed, VSTO 2005 SE Beta replaces it with the new InfoPath 2007 form project template.

VSTO 2005 is the technology that brings the power and productivity of Visual Studio .NET and the .NET Framework to business solutions built on Microsoft Word 2003, Microsoft Outlook 2003, Microsoft Excel 2003 or Microsoft InfoPath 2003.

Microsoft Visual Studio 2005 Tools for the Microsoft Office System (VSTO 2005) Redistributable Package (x86) - Download

The VSTA SDK is installed as part of the Visual Studio SDK. Download Visual Studio 2005 SDK - February 2006

Wednesday, October 04, 2006

Creating Files using ASP.NET code behind VB.NET -- Save a file to a specific directory

In ASP.NET we can create a file and save it in a particular directory, to do the operation we have two different ways. One is using Response.Write("STRING") and another one is filestream.

First let me give you the sample code using Response.Write("STRING").

Code Sample using Response.Write("STRING"):

Imports System
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.SqlClient

Public Class WebForm1
Inherits System.Web.UI.Page

Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim filename As String
Dim dr As SqlDataReader
Dim i As Integer
Dim sb As System.Text.StringBuilder

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click
cn = New SqlConnection("server=localhost;uid=sa;pwd=;database=northwind")
filename = "products.csv"
cmd = New SqlCommand("select * from products ", cn)
cmd.Connection.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
sb = New System.Text.StringBuilder


'For field Names
For i = 0 To dr.FieldCount - 1
If i < (dr.FieldCount - 1) Then

sb.Append(Chr(34) & dr.GetName(i) & _ Chr(34) & ",")
Else
sb.Append(Chr(34) &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;
dr.GetName(i) & _ Chr(34) & vbCrLf)
End If Next

'For field Values
While dr.Read()
For i = 0 To dr.FieldCount - 1
If i < (dr.FieldCount - 1)
Then
sb.Append(Chr(34) & _ dr.GetValue(i).ToString & Chr(34) & ",")
Else
sb.Append(Chr(34) & _ dr.GetValue(i).ToString & Chr(34) & vbCrLf)
End If Next
End
While dr.Close()
cn.Close()
Response.ContentType = "Application/x-msexcel" Response.AddHeader _ ("content-disposition", "attachment; filename=""" & _ filename & """")

'Write the file directly to the HTTP output stream.

Response.Write(sb.ToString)
Response.End()
End Sub
End Class

Code Sample using filestream:

Imports System
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO

Public Class WebForm1
Inherits System.Web.UI.Page

Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim filename As String
Dim dr As SqlDataReader
Dim i As Integer
Dim sb As System.Text.StringBuilder


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cn = New SqlConnection("server=localhost;uid=sa;pwd=;database=northwind")
filename = "products.csv"
cmd = New SqlCommand("select * from products ", cn)
cmd.Connection.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
sb = New System.Text.StringBuilder

'For field Names
For i = 0 To dr.FieldCount - 1
If i < (dr.FieldCount - 1)

Then
sb.Append(Chr(34) & dr.GetName(i) & Chr(34) & ",")
Else sb.Append(Chr(34) &amp;amp;amp;amp;amp;amp;amp;
dr.GetName(i) & Chr(34) & vbCrLf)
End If
Next
'For field Values
While dr.Read()
For i = 0 To dr.FieldCount - 1
If i < (dr.FieldCount - 1)
Then
sb.Append(Chr(34) & dr.GetValue(i).ToString & Chr(34) & ",")
Else
sb.Append(Chr(34) & dr.GetValue(i).ToString & Chr(34) & vbCrLf)
End If
Next
End While
dr.Close()
cn.Close()
// FileStream to create files
Dim fs As New FileStream("c:\products0.csv", FileMode.Create, FileAccess.Write)
Dim s As New StreamWriter(fs)
s.BaseStream.Seek(0, SeekOrigin.End)
s.WriteLine(sb.ToString) s.Close()
End Sub
End Class


These are the two simple ways to create files using VB.NET.

ASP.NET MVC - Sport Facility Booking system

  The project relies on some external service providers. Thus accessing them via their API requires authentication. An API Key need to be su...