vbdotnet.it

Tricks & tips, workaround, forum and ideas with .Net

About the author

Enrico Rossini è il gestore di questo blog.
E-mail me Send mail

Recent posts

Recent comments

Contributi

Best 6 ~ 6 users ~ 6 comments

Info legali

Le opinioni espresse in questo blog sono strettamente personali e ogni persona è responsabile dei commenti che inserisce. I marchi citati sono delle rispettive aziende.

© Copyright 2010

Advertising


Microsoft Report: aggiungere il numero di riga ad una tabella

Quando si crea una tabella con dei dati in Microsoft Report è tutto abbastanza facile. Un problema che non sapevo come risolvere era quello di inserire un numero di riga progressivo. Non ho trovato molte indicazioni su come fare ma poi ho sparato un'idea e ha funzionato.Il comando da eseguire nella cella dove visualizzare i numeri progressivi è la seguente:

=RowNumber(Nothing)

Facile, no? Ciao e buon lavoro a tutti!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Friday, January 22, 2010 5:48 PM
Permalink | Comments (0) | Post RSSRSS comment feed

contextSwitchDeadlock MDA

Questo errore fortunatamente compare solamente durante il debug di un'applicazione: semplicemente avverte che l'operazione che si sta effettuato sta impiegando molto tempo e risorse. Se però si clicca comunque su "Play" l'applicazione continua a proseguire normalmente la sua attività.

Diversi sono i link interessanti a proposito che vi segnalo:

L'ultimo link è forse quello più completo. Buon lavoro!

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Friday, November 06, 2009 6:27 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Directory del programma

Ciao, questo è un semplice tricks. Molto spesso accade che si vuole sapere in quale directory gira il nostro programma. COn questa semplice riga lo si sa.

Private myFileName As String = System.Reflection.Assembly.GetExecutingAssembly().Location
myFileName = myFileName.Substring(0, myFileName.LastIndexOf("\"))

Attenzione. La funzione System.Reflection.Assembly.GetExecutingAssembly().Location restituisce anche il nome del file eseguibile. Per questo è stato necessario aggiungere la riga sottostante. Buon lavoro.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Tuesday, July 28, 2009 12:46 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Invio email con framework 3.5

Con il .NET framework 3.5 è stato introdotto un nuovo namespace Mail per l’invio delle email: questo namespace può essere aggiunto ai nostri programmi con la seguenti riga di codice:

Imports System.Net.Mail

L’invio dell’email può presentare qualche problema poiché non si trovano molti esempi su come inviare ad esempio degli allegati o ricevere una conferma di lettura. Nell’esempio che segue cercherò di rispondere a questi problemi.

Si supponga di avere un form con i seguenti textbox: txtTo per inserire l’email a cui spedire, txtSubject per inserire l’oggetto del messaggio, txtMessage per il corpo del messaggio e un listbox di nome lstAttachment per visualizzare l’elenco degli allegati. Un bottone per l’invio ed un checkbox per voler spedire il messaggio come HTML.

Dim objSmtpMail As System.Net.Mail.SmtpClient       ' variabile generale per l'invio dell'email
Dim Attachment As System.Net.Mail.Attachment        ' variabile per salvare gli allegati
Dim Mailmsg As New System.Net.Mail.MailMessage()    ' variabile per creare il corpo del messaggio
 
Private _displayname As String = ""                 ' variabile che contiene il nome dell'email da visualizzare
Private _from As String = ""                        ' variabile con l'indirizzo email da cui spedire
Private _smtpserver As String = ""                  ' variabile contenente l'indirizzo del server mail
 
Public Sub SendEmail()
   ' imposta le proprietà del server
   objSmtpMail = New System.Net.Mail.SmtpClient(_smtpserver)
 
   ' definisce il mittente 
   ' (primo parametro l'indirizzo email, secondo il nome che deve apparire all'utente che riceve l'email)
   Mailmsg.From = New System.Net.Mail.MailAddress(_from, _displayname)
 
   ' per specificare indirizzi multipli separare uno dall'altro con il ;
   Mailmsg.To.Add(New System.Net.Mail.MailAddress(Me.txtTo.Text.Trim))
 
   ' specifica formato
   If Me.tsbHTML.Checked = True Then
      ' spedisce l'email in formato HTML
      Mailmsg.IsBodyHtml = True
   Else
      Mailmsg.IsBodyHtml = False
   End If
 
   ' aggiunge degli header all'email che consentono di ricevere la conferma di lettura
   Mailmsg.Headers.Add("Reply-To", Mailmsg.From.Address)
   Mailmsg.Headers.Add("Disposition-Notification-To", Mailmsg.From.Address)
   Mailmsg.Headers.Add("Return-Receipt-To", Mailmsg.From.Address)
 
   ' aggiunge il testo
   Mailmsg.Subject = txtSubject.Text
   Mailmsg.Body = txtMessage.Text
 
   ' aggiunte gli allegati
   For Counter = 0 To lstAttachment.Items.Count - 1
      Attachment = New System.Net.Mail.Attachment(lstAttachment.Items(Counter))
      Mailmsg.Attachments.Add(Attachment)
   Next
 
   ' spedisce effettivamente l'email
   objSmtpMail.Send(Mailmsg)
End Sub

Spero vi sia utile. Ciao!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Tuesday, July 21, 2009 12:03 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Un metodo velocissimo per leggere un RSS

Questo è il più semplice modo per leggere un RSS... 

Dim ds as DataSet = new DataSet()
ds.ReadXml("http://www.vbdotnet.it/syndication.axd",XmlReadMode.Auto)

DataGrid1.DataSource=ds.Tables(2)
DataGrid1.DataBind()

Ciao a tutti!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Thursday, April 30, 2009 1:46 PM
Permalink | Comments (0) | Post RSSRSS comment feed

L'usercontrol è in ambiente di designtime?

Se si è alle prese con la realizzazione di un Usercontrol potrebbe essere utile determinare se il componente stesso si trova in design-time (come ad esempio all’interno di un form in Visual Studio) o se è in runtime.

Per poter verificare questo basta utilizzare il seguente codice:

   1: ' verifica se il componente è in esecuzione a runtime
   2: If System.ComponentModel.LicenseManager.UsageMode = LicenseUsageMode.Runtime Then
   3:    ' esegue altro codice
   4: End If

Ciao.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Thursday, April 16, 2009 7:30 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Togliere lo scrollbar da un textbox quando non server

Non so se anche a voi è capitato ma mi sembra utile postarlo. Se hai un TextBox con una scrollbar e vuoi nascondere la scrollbar quando questa è inutile, come si può fare?

Ecco il codice (txtTesto è il nostro TextBox):

   1: Private Sub txtTesto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTesto.TextChanged
   2:     Static busy As Boolean
   3:     If busy Then Exit Sub
   4:     busy = True
   5:  
   6:     With sender
   7:         Dim tS = TextRenderer.MeasureText(.Text, .Font)
   8:         Dim Hsb = .ClientSize.Height < tS.Height + .Font.Size
   9:         Dim Vsb = .ClientSize.Width < tS.Width
  10:  
  11:         If Hsb And Vsb Then
  12:             .ScrollBars = ScrollBars.Both
  13:         ElseIf Not Hsb And Not Vsb Then
  14:             .ScrollBars = ScrollBars.None
  15:         ElseIf Hsb And Not Vsb Then
  16:             .ScrollBars = ScrollBars.Vertical
  17:         Else
  18:             .ScrollBars = ScrollBars.Horizontal
  19:         End If
  20:     End With
  21:     busy = False
  22: End Sub

Ciao!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Friday, April 10, 2009 1:42 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Leggere un file Microsoft Excel 97/2003 o 2007

La funzione che presento oggi consente di importare un foglio di Microsoft Excel in un dataset nelle versioni 97, 2003 e 2007.

 

   1: ''' <summary>
   2: ''' Reads the data from excel.
   3: ''' </summary>
   4: ''' <param name="excelfilename">The excelfilename.</param>
   5: ''' <returns></returns>
   6: Function ReadDataFromExcel(ByVal excelfilename As String) As DataSet
   7:     Dim ds As New DataSet
   8:     Dim da As OleDbDataAdapter
   9:     Dim conn As OleDbConnection
  10:  
  11:     Try
  12:         If System.IO.Path.GetExtension(excelfilename) = ".xls" Then
  13:             conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & excelfilename & "; Extended Properties=Excel 8.0;")
  14:         ElseIf System.IO.Path.GetExtension(excelfilename) = ".xlsx" Then
  15:             conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & excelfilename & "; Extended Properties=Excel 8.0;")
  16:         End If
  17:  
  18:         da = New OleDbDataAdapter("SELECT * FROM [Foglio1$]", conn)
  19:  
  20:         conn.Open()
  21:         da.Fill(ds)
  22:     Catch ex As Exception
  23:         MsgBox(ex.Message)
  24:     Finally
  25:         If conn.State = ConnectionState.Open Then
  26:             conn.Close()
  27:         End If
  28:     End Try
  29:     ReadDataFromExcel = ds
  30: End Function

Buon lavoro e ricordatevi il nostro forum!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Tuesday, April 07, 2009 7:32 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Aggiungere uno script JS ad un ScriptManager (ad esempio JQuery)

Utilizzando Ajax può capitare di dover inserire uno script JS all’interno della pagina. Per poterlo fare basta utilizzare la seguente sintassi:

   1: <asp:ScriptManager ID="ScriptManager1" runat="server">
   2:    <Scripts>
   3:       <asp:ScriptReference Path="~/js/jquery/jquery-1.2.6.min.js" />
   4:    </Scripts>
   5: </asp:ScriptManager>

Buon lavoro!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Monday, March 23, 2009 3:24 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Caricare 2 dfferenti report in Microsoft ReportViewer

Non so se ha te è capitato di dover caricare diversi Report fatti con il tool di Microsoft e vedersi restituire degli errori di vario tipo. Ad esempio a me è capitato che due report aventi parametri diversi mi creavano dei problemi quando li andavo a visualizzare.

Per poter risolvere il problema è necessario effettuare un refresh del report poiché sembra che il ReportViewer tenga in memoria le informazioni del report definiti durante la creazione in design-time.

Per poter risolvere il problema si possono utilizzare le seguenti righe di codice:

   1: Dim rds As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource
   2: Me.ReportViewer1.Reset()
   3: Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "report.rdlc"
   4: Me.ReportViewer1.LocalReport.DataSources.Clear()
   5: rds.Name = "nome_dataset_del_report"
   6: rds.Value = Me.CommesseAttivitaBindingSource
   7: Me.ReportViewer1.LocalReport.DataSources.Add(rds)

Buon lavoro!

P. S.: abbiamo creato il nostro forum per poter rispondere alle vostre domande. Utilizzatelo numerosi! Grazie

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Monday, March 09, 2009 7:11 PM
Permalink | Comments (0) | Post RSSRSS comment feed