Development Blog : C# Code Samples,.NET Tips and Tricks
Post con tag Tips and Tricks
Come rimuovere tutti i tag HTML da una stringa con Visual C#
21 giu
using System.Text.RegularExpressions;
...
const string HTML_TAG_PATTERN = "<.*?>";
static string StripHTML (string inputString)
{
return Regex.Replace(inputString, HTML_TAG_PATTERN, string.Empty);
}
Come eliminare i file temporanei di Internet con Visual C#
18 giu
Ecco una semplice procedura per eliminare la cache di Microsoft Internet Explorer con Visual C#
using System.IO;
...
void clearIECache()
{
ClearFolder (new DirectoryInfo (Environment.GetFolderPath
(Environment.SpecialFolder.InternetCache)));
}
void ClearFolder (DirectoryInfo folder)
{
foreach (FileInfo file in folder.GetFiles())
{ file.Delete(); }
foreach (DirectoryInfo subfolder in folder.GetDirectories())
{ ClearFolder(subfolder); }
}
public static void Main( )
{
new Test().clearIECache ();
}
[C#] : Come scansionare un Array con LINQ
12 giu
[ad] Slot Pubblicità #4 vuoto!
using System;
using System.Collections;
using System.Collections.Generic;
namespace ForEachExaple
{
public static class Utility
{
public static void ForEach(this IEnumerable coll, Action function)
{
IEnumerator en = coll.GetEnumerator();
while (en.MoveNext())
function(en.Current);
}
}
class Program
{
static void Main(string[] args)
{
var array = new int[] { 1, 2, 3 };
//Output : 123
array.ForEach(val => Console.Write(val));
}
}
}
[C#] : Come inviare una mail con gmail
10 giu

Ecco un metodo sempice e veoloce per inviare una mail da Gmail con C# :
1 2 3 4 5 6 7 8 9 10 11 12 13 | string host = "smtp.gmail.com"; int port; //port = 587; // with TLS //port = 465; // with SSL port = 25; // normal ‐ works for my gmail account with enableSSL string fromEmail = "myemail@mydomain.com"; var fromAddress = new MailAddress(fromEmail); var toAddress = new MailAddress("myemail@aDifferentDomain.com"); MailMessage message = new MailMessage(fromAddress, toAddress) { Subject = "subject", Body = "body", }; |
[ad] Slot Pubblicità #4 vuoto!
Continua >[C#] : Come passare da Excel a Datatable
10 giu
1 2 3 4 5 6 7 8 9 10 | string connectionString = string.Format("Provider = Microsoft.Jet.OLEDB.4.0; data source = {0};Extended Properties=Excel 8.0;",file); OleDbDataAdapter = new OleDbDataAdapter("SELECT * FROM [TABLES1$]",connectionString); DataSet ds = new DataSet(); adapter.Fill(ds,"Name"); DataTable dt = ds.Tables["Name"]; |
[ad] Slot Pubblicità #4 vuoto!
[VB.NET] : Popolare una DataTable con un file CVS
20 mar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | Function ReadCSV(ByVal path As String) As System.Data.DataTable Dim sr As New StreamReader(path) Dim fullFileStr As String = sr.ReadToEnd() sr.Close() sr.Dispose() Dim lines As String() = fullFileStr.Split(ControlChars.Lf) Dim recs As New DataTable() Dim sArr As String() = lines(0).Split(","c) For Each s As String In sArr recs.Columns.Add(New DataColumn()) Next Dim row As DataRow Dim finalLine As String = "" For Each line As String In lines row = recs.NewRow() finalLine = line.Replace(Convert.ToString(ControlChars.Cr), "") row.ItemArray = finalLine.Split(","c) recs.Rows.Add(row) Next Return recs End Function |
[VB.NET] : Accesso in lettura ad una DataTable
20 mar
1 2 3 4 5 6 7 | Function ReadAccess(ByVal sqlString As String, ByVal path As String) As System.Data.DataTable Dim strConn As String = _"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";" Dim recs As New Data.DataTable() DIm sql As New OleDbDataAdapter(sqlString, strConn) sql.Fill(recs) Return recs End Function |
![Last Minute last60 225x300 [C#] : Come scansionare un Array con LINQ](http://www.luigimelisi.com/wp-content/uploads/2010/06/last60-225x300.jpg)