Wednesday, June 30, 2010

What School Did Myamee Go Tofam U

Load data from an XML file in VB.Net

If you're one of those guys who do not want life difficult trying to store in a database each parameter that was presented derrepente to initialize the application that opens the doors of your system, as I have here a practical solution in VB.net using file XML boot, maybe the term you paresca strange but it's not complicated if you only want to initialize only values \u200b\u200bin a form whatsoever, and here is the solution: Just just place the following code into a file text and change its original extension (. txt) and XML for this to become as such, or perhaps have been more inquisitive and I have noticed that there is a section in the versions of VB.Net to create this file: Menu Project -> Add New Data Element ...--> ---> XML File




XML:


< companies >

< company name = " EMPRESA1 " bd =" BD_ EMPRESA1 "/>

< company name = " EMPRESA2 " bd = " BD_ EMPRESA2 "/>

< company name = " EMPRESA3 " bd = " BD_ EMPRESA3 " />

< company name = " EMPRESA4 " bd = " BD_ EMPRESA4 "/>

companies >


VB.net Code :


Dim _dsdetalle As DataSet 'I have decided to fill the xml data in a data set in the first instance as this me serve to link or fill in the data after a certain combo that eleji to display the information contained in the xml

Private Sub FRM_Load ( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load

Dim Xml As XmlDocument

Dim NodeList As XmlNodeList

Dim Node As XmlNode

Dim _DS As New DataSet

LlenarDS()

Try

Xml = New XmlDocument ()

XML.load (Application.StartupPath & "\\ Inicio.xml " ) 'eye this is the address of the folder where you run the program (software, application, system, etc) because that is where prinicipal I have kept Inicio.xml



NodeList = Xml.SelectNodes( "/empresas/empresa" )

For Each Node In NodeList

Dim rw As DataRow = _dsdetalle.Tables (0). NewRow

rw ( "razon_social" ) = Node.Attributes . getNamedItem ( " name " ) . Value

rw ( "bd" ) = Node.Attributes . GetNamedItem ( "bd" ). Value

_dsdetalle.Tables (0). Rows.Add (rw)

Next

CboEmpresa.DisplayMember = "razon_social"

CboEmpresa.ValueMember = "bd"

CboEmpresa.DataSource _dsdetalle.Tables = (0)

Catch ex As Exception

MsgBox(ex.GetType.ToString &amp; vbNewLine &amp; ex.Message.ToString)

Finally

Console.Read()

End Try

End Sub

'We shape our dataset in a separate thread that links your content to the combo

Private Sub LlenarDS ()

_dsdetalle = New DataSet

_dsdetalle.Tables.Add(0)

With _dsdetalle.Tables(0).Columns

.Add( "razon_social" , System.Type.GetType( "System.String" ))

.Add( "Bd" , System.Type.GetType ( "System.String" ))

End With

End Sub

Tuesday, June 22, 2010

Hyperactivity More Condition_symptoms

Check the connection to an FTP server in vb.net

Now, we have the following problem, is that Sometimes we are slow line o en el peor de los casos algun gracioso desconecto nuestro servidor FTP y todos los archivos que se tratan de enviar no llegan a su destino ya que si no nos apresuramos nos pueden linchar los usuarios de nuestro sistema, bueno aca esta claro que hay un problema de conectividad, para cualesquiera que sea el caso, es necesario verificar (validar, comprobar, etc etc) justamente si esta disponible nuestro server en ese momento que que enviamos o descargamos los archivos y de esa forma apaciguar los animos de quienes lo requieren con un mensaje como "La linea que Telefonica nos provee esta pesima, asi que tranquilizate e intenta mas tarde enviar tu archivo".

Pues bien ahora mostrare un fragmento de como resolver (en todo caso, advertir) este problemilla in Visual Basic 2008 code

Code:

Private Function VerificarConecFTP () As Boolean

ClienteFtp Dim As New Sockets. TcpClient

Try

ClienteFtp.Connect ( "2oo.48.xx.xxx" , 21) 'eye, only IP the FTP server

ConectarFTP = True 'if True returns means that there is connection

Catch Ex As Exception

MsgBox (ex.Message ) 'write the message but save you trouble

ConectarFTP = False' if it returns False means you have to go running to see what happens on the server

End Try

End Function

Music Express Physics

How to download or download a file from an FTP server vb.Net

The previous article gave an example in which our system company aims to control all the files that our users are sending to each other and in which we had to we, as programmers, to see how how to upload or send a file to an FTP server in vb.net (or otherwise We said goodbye to the job), now I Decoding the code to its counterpart: download or download a file. As
we had stated in another topic, here are some additional recommendations:


* Having a good internet line, and less quick to download (or slower) to upload a file to a server, this consideration is very important because occasion could fail if the timeout expires for a connection to the FTP that is usually to have a pessimistic line.
* required fields have in our DB (SQL Server assume) for it to be effective to control such transfers of files, the data as the file name, user name remitenete and destination, time and date of receipt will be the keys to good control.
* Well, needless to say that they have have an FTP server where you store and where "jalaran" files to each user's PC to access them from anywhere in the world and from any era of a very distant future.

This is the code example in Visual Basic 2008

Where path filename would come to be the folder on your hard drive where the downloaded file will be saved and could be "c: \\ downloads \\ nombre_original_segun_BD.doc" Filename and the name which is stored in the FTP server, if we look good parameters would have no trouble getting the file to which you want to access each file and supposedly in the FTP server is registered in Database, here is the importance of keeping the data that are related to the file.


Public Sub DescargarArchivoFTP (ByVal path filename As String , ByVal FileName As String )

Dim LocalFiles As String = path filename

remotefile Dim As String Filename =

Const host As String = "ftp://xxx.xx.xx.xxx/archivos/" 'name of the folder in our server FTP where are the files you want to download

'put the username and password to access the respective server, if it does not possess, let alone the quotes, I mean " "

Const username As String = "user"

Const password As String = "password"

Dim URI As String = host & remotefile 'full name of the file path

Dim ftp As System.Net.FtpWebRequest = CType (Net.FtpWebRequest.Create (URI), Net.FtpWebRequest)

ftp.Credentials = New _

System.Net.NetworkCredential (username, password)

ftp.KeepAlive = False

ftp.UseBinary = True

ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

Try

Using response As System.Net.FtpWebResponse = _

CType (ftp.GetResponse, System.Net.FtpWebResponse)

Using responseStream As IO.Stream = response.GetResponseStream

Using fs As New IO.FileStream(localFile, IO.FileMode.Create)

Dim buffer(2047) As Byte

Dim read As Integer = 0

Do

read = responseStream.Read(buffer, 0, buffer.Length)

fs.Write(buffer, 0, read)

Loop Until read = 0

responseStream.Close()

fs.Flush()

fs.Close()

End Using

responseStream.Close()

End Using

response.Close()

End Using

Catch ex As Exception

MsgBox (ex.Message)

End Try

End Sub

Monday, June 21, 2010

Constant Prostate Pain

How to send a file to an FTP server in VB. Net

The issue is this: We charge an application or a module within our main system, which can be sending and receiving files (documents or whatever) which is contained in important information for the company to one or more users which will target just the file. For this will take into account sieguiente:

* Have a PC or FTP server where they were stored and accessed from anywhere in the world and at any time to the files.
* Have the appropriate fields in a table in our BD code indicating the user's file name (ejemplo.doc) etc.
* Having a good internet line
Eye
here and I will not detail that code used in vb.net and SQL Server to save the parameters in the database of the fields mentioned, because that will be defined for every programmer only show you an example of how to send a file from FTP:

Code: Where
OrigenArchivo
might be "c: \\ ejemplo.doc" and could be FileName "Archiv0_0001.doc" because I recommend using a correlative when you name the file on the FTP server as occasion may fail if the ship with a name of a file that already exists in the destination folder created on the FTP server, eh hence the importance of keeping the data name (ejemplo.doc) so that when receiving or downloading the file is saved to local disk with the original name.


Public Shared Sub EnviarArchivoFTP ( ByVal OrigenArchivo As String, ByVal FileName As String )

clsRequest Dim As System.Net.FtpWebRequest

Dim connection As Net.Sockets.TcpClient

clsRequest = DirectCast (System.Net.WebRequest.Create ( "ftp:// xxx.xx.xxx.xxx / files / filename) System.Net.FtpWebRequest)

clsRequest.Proxy = Nothing 'This assignment is important to work on Windows XP and by default this property is to be assigned to an http server which ocacionaria an error if we want to connect to an FTP site in Windows Vista and Seven have not had this problem.

clsRequest.Credentials = New System.Net.NetworkCredential ( "user" , "password" ) 'Username and password to access the FTP server, if not tubiese, leave quotes, osea "

clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

Try

bFile Dim () As Byte = System.IO. File.ReadAllBytes (origenArchivo)

Dim clsStream As System.IO.Stream = _

clsRequest.GetRequestStream()

clsStream.Write(bFile, 0, bFile.Length)

clsStream.Close()

clsStream.Dispose()

Catch ex As Exception

MsgBox (ex.Message & . "The file could not be sent, try later" )

End Try

End Sub