Development Blog : C# Code Samples,.NET Tips and Tricks
Articoli con tag Code Samples
Come eliminare i file temporanei di Internet con Visual C#
01 year ago un anno fà
Scritto da Luigi Melisi
in Tips and Tricks
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 ();
}
Come visualizzare tutti i nomi dei database Sql Server con Visual C#
01 year ago un anno fà
Scritto da Luigi Melisi
in Tips and Tricks
Nell’esmpio riportato di seguito, vi riporto una semplice procedura per recuperare tutti i nomi dei database sql server utilizzando Visual C# :
using System.Data;
using System.Data.SqlClient;
...
// Sostituire con la propria stringa di connessione
String conxString = "Data Source=MYSERVER; Integrated Security=True;";
using (SqlConnection sqlConx = new SqlConnection (conxString))
{
sqlConx.Open();
DataTable tblDatabases = sqlConx.GetSchema ("Databases");
sqlConx.Close();
foreach (DataRow row in tblDatabases.Rows)
{
Console.WriteLine ("Database: " + row["database_name"]);
}
}
Come scrivere una chiave nel registro di Windows con Visual C#
01 year ago un anno fà
Scritto da Luigi Melisi
in Tips and Tricks
using Microsoft.Win32;
...
RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Test\\Preferences");
if (masterKey == null)
{
Console.WriteLine ("Null Masterkey!");
}
else
{
try
{
masterKey.SetValue ("MyKey", "MyValue");
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
}
finally
{
masterKey.Close();
}
}
Come leggere una chiave dal registro di Windows con Visual C#
01 year ago un anno fà
Scritto da Luigi Melisi
in Tips and Tricks
Nell’ esempio che segue viene mostrato come leggere una chiave del registro di Windows utilizzando Visual C# ed il .Net Framework :
using Microsoft.Win32;
...
RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Test\\Preferences");
if (masterKey == null)
{
Console.WriteLine ("Null Masterkey!");
}
else
{
Console.WriteLine ("MyKey = {0}", masterKey.GetValue ("MyKey"));
}
masterKey.Close();
[WordPress] : Come contare i commenti dei Post
01 year ago un anno fà
<? $pop = $wpdb->get_results(SELECT ID,post_title,comment_count FROM {$wpdb->prefix} posts WHERE post_type ='post' ODER BY comment_count DESC LIMIT 10 );
foreach($pop as $post) : ?>
<li> <?php echo $post->post_title; ?> </li>
<?php endforeach; ?>
[C#] : Come scansionare un Array con LINQ
01 year ago un anno fà
Scritto da Luigi Melisi
in Tips and Tricks
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
11 year ago un anno fà
Scritto da Luigi Melisi
in Tips and Tricks
![fuori tutto youbuy pcfuori [C#] : Come inviare una mail con gmail](http://www.luigimelisi.com/wp-content/uploads/2010/06/pcfuori.jpg)
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", }; |
[C#] : Come passare da Excel a Datatable
01 year ago un anno fà
Scritto da Luigi Melisi
in Tips and Tricks
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"]; |

![Last Minute last60 225x300 [C#] : Come scansionare un Array con LINQ](http://www.luigimelisi.com/wp-content/uploads/2010/06/last60-225x300.jpg)