|
I have .CSV file on my machine. That file doesn't exist on FTP server.i have to write a code in vb.net which checks if the file doesn't exist on server, then only FTP the file.
I have written a small code that does simple FTP and not checks existance of the file on server.
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create("ftp://127.0.0.1/Book1.csv"), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential("me", "test")
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
clsRequest.KeepAlive = False
clsRequest.UseBinary = True
' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes("C:\FTP\Book1.csv")
' upload file...
Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream() -- the Code gives error here
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()
Can you please help me.
|
|
|
|
|
I use this simple code
Try
My.Computer.Network.UploadFile(f.Local, f.FTP.ToLower, .Login, Functions.fEncode(.Paswoord))
Catch ex As Exception
sError = ex.Message
sMessage = ex.Message
End Try
I think its easy to transform
the vars sError and sMessage are there becourse I use them later to show all errors in one message
Jan
|
|
|
|
|
The problem with the code above :
DirectCast(System.Net.WebRequest.Create("ftp://127.0.0.1/Book1.csv"), System.Net.FtpWebRequest)
is that Book1.csv doesn't exist on server. So in code line:
Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
when it try to read the stream, it doesn't find the file and gives error "the File does not exist"
|
|
|
|
|
hi,
you can use this: http://www.codeproject.com/KB/IP/FTP_Secure.aspx[^]
it's An FTP secure client library for C# (NOT VB.Net sorry)!
to checks existance of the file on server:
FTPFactory ff = new FTPFactory();
ff.setDebug(true);
ff.setRemoteHost(Settings.Default.SourceFtpHost);
ff.setRemoteUser(Settings.Default.SourceFtpUser);
ff.setRemotePass(Settings.Default.SourceFtpPass);
ff.login();
ff.chdir("in");
string[] fileNames = ff.getFileList(string FileMask));
if (fileNames == null || fileNames.Length == 0)
{
throw new Exception("No File was found");
}
|
|
|
|
|
Hi. I'm busy with a app that needs to print xml rendered by xslt. Currently I am printing with internet explorer in the following manner
Dim internetExplorer As New SHDocVw.InternetExplorerClass()
Dim webBrowser As SHDocVw.IWebBrowser2 = CType(internetExplorer, SHDocVw.IWebBrowser2)
'Make the web browser visible
webBrowser.Visible = False
'Display empty page so we have something to manipulate.
Dim noValue As Object = System.Reflection.Missing.Value
webBrowser.Navigate("file://" + fileName, noValue, noValue, noValue, noValue)
While webBrowser.Busy
Threading.Thread.Sleep(500)
End While
'Get access to the webbrowser's document.
internetExplorer.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, noValue, noValue)
'CType(internetExplorer.Document, mshtml.IHTMLDocument2).close()
Marshal.ReleaseComObject(internetExplorer)
Marshal.ReleaseComObject(webBrowser)
I need to find a different way to do this as the above code gives a com exception. Or I need a workaround for the above code. If anybody can help I would greatly appreaciate it.
Stephen
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
how to bind checkedlistbox with dataset in vb.net (window application)
Er. Jagwinder Singh
|
|
|
|
|
Typing your exact words into Google revealed a bunch of articles on that very subject.
Google results...[^]
|
|
|
|
|
I'm trying to use a class in place of a property and need help with getting the Reflection correct.
Here is a very simple example of what I'm doing:
Public Class Contact
Dim _contactID As zyp_ContactID
Public Sub New()
End Sub
Public Property ContactID() As Guid
Get
Return _contactID.value
End Get
Set(ByVal value As Guid)
_contactID.value = value
End Set
End Property
Public Class zyp_ContactID
Protected Friend Sub New()
End Sub
Dim _contactID As Guid
Public Property value() As Guid
Get
Return _contactID
End Get
Set(ByVal value As Guid)
_contactID = value
End Set
End Property
End Class
End Class
br mode="hold" />
In my previous work I've always just had public properties and used Refelection to hydrate from the database. This allowed me to have a Services class that handled all the hydration through a DatabaseHelper class. There was only one class for each business object that handled hydrating and only one class for the whole program which interfaced to the database. Switching to a different database or even to XML or Web Services was just a one-class change (at least as far as the application code was concerned).
I've run into some real limitations with Properties and creating subclasses appears to be the solution.
I previously used code from Chris Rock, <a href="http://www.rocksthoughts.com/blog/archive/2008/04/24/creating-a-datarow-to-customer-object-mapper.aspx">http:
So now I need help with the following:
For each property in the class
1. Is the property a class ?
2. If so, does the class have a property of "value" ?
3. If so, can we write to the property "value" ?
4. If so, write to the property "value".
Any hints are greatly appreciated...I'm stuck on this and hate the idea of not being able to use a generic mapper class.
As an alternative, is there a way to pass a reference to a function to a sub so that the sub can call the function referenced. This is a backup option if I can't get the generic mapper class to work.
|
|
|
|
|
Your question's formatting is a bit screwed up, making it hard to read. But, I think you're trying to reflect down into child properties of a child class of a class to set it's properties. If so, why? Wouldn't you just create a instance of the target class, set it's properties, then just assign that object to the parent class property? Or am I missing something??
|
|
|
|
|
You are correct that my question formatting is messed up. Unfortunately, I do not see any way to edit my post.
You are correct in what I'm trying to do.
I can't create an instance of the child class as that is handled by the parent class's constructor. Even if I could I would still need to use reflection to determine the child class to create and to assign a value to its "value" property.
|
|
|
|
|
In the bottom right corn of any message you post, you can click on Edit while viewing it.
In that case, I would imagine that you have to pass the new child class to the same code you're already using to fill in the fields and call methods of the parent class. Though, this depends on your parent class' implementation of hosting the child class, if it's a poperty or just a public field. Kind of like recursion walking a directory tree.
|
|
|
|
|
HI - and Help !
I have a small working app that formats a request to Google Maps, an retireves the data.
I copied the code to access a USGS site - and the string works but the code hangs.
Here is the code
Sub GetElevationData()
'This is based upon GoogleMaps access code
'WebRequestString = "http://ws.geonames.org/gtopo30?lat=" & lineArray(LatPosition) & "&lng=" & lineArray(LonPosition) ' this is the eventual string . . . but I am using the following as a test - I can ctrl click and the link comes up ok with a 2 digit elevation.
Dim test1 As String = "http://ws.geonames.org/gtopo30?lat=33.7669399&lng=-116.4134417"
' documentation is available at http://www.geonames.org"
Dim Request As HttpWebRequest = CType(WebRequest.Create(test1), HttpWebRequest)
'Request.MaximumAutomaticRedirections = 5 Tried these (and lots other options - but no joy)
'Request.AllowAutoRedirect = True
Dim Response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse)
'This seems to time out
Dim str As Stream = Response.GetResponseStream()
Dim inBuf(10000) As Byte
Dim bytesToRead As Integer = CInt(inBuf.Length)
Dim bytesRead As Integer = 0
While bytesToRead > 0
Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)
If n = 0 Then
Exit While
End If
bytesRead += n
bytesToRead -= n
End While
MsgBox("bytesread " & bytesRead) 'says 4
'inBuf now has the elevation
'bytesRead has the string length
Dim elevationvalue As String = inBuf.ToString
MsgBox(elevationvalue) ' says system byte []
'lineArray(elevationPosition) = elevationvalue
Response.GetResponseStream().Dispose()
End Sub
Thanks
Bob
|
|
|
|
|
Just a couple of questions off the top of my head... Hangs where?? Which line?? Does it hang for a time, then resume?? Does it hang indefinately?? What's the size of the file it's trying to retrieve?? Is there network activity during the hang??
|
|
|
|
|
HI - and thanks for the reply If you want to chat about this - call me at 510 889 1453
I Posted this reply a bit early - and have found a small glitch
I have modified the code a bit - here is the most recent version using a directcast . . . The other version hung on the response statement - forever - and the network is basically empty during the hang
The reply is a 1-4 byte string. ---> Glitch - the directcast returns the entire web page string -
I found the following as an alternate suggestion - it works - but seems to time out on each request (my test file has 2 records, and the total time is about 12 seconds) - but if I un-comment the test1 string I get sub second response to a browser window.
My DevEnv is VisualStudio2008
WebRequestString = "http://ws.geonames.org/gtopo30?lat=" & lineArray(LatPosition) & "&lng=" & lineArray(LonPosition)
'Dim test1 As String = "http://www.geonames.org/gtopo30?lat=33.7669399&lng=-116.4134417"
Dim Request As HttpWebRequest
Dim Response As HttpWebResponse
Dim reader As StreamReader
Dim sbSource As StringBuilder
Try
Request = DirectCast(WebRequest.Create(WebRequestString), HttpWebRequest)
Request.KeepAlive = False
response = DirectCast(Request.GetResponse(), HttpWebResponse)
If Request.HaveResponse = True AndAlso Not (response Is Nothing) Then
' Get the response stream
reader = New StreamReader(response.GetResponseStream())
' Read it into a StringBuilder
sbSource = New StringBuilder(reader.ReadToEnd())
End If
Catch wex As WebException
' This exception will be raised if the server didn't return 200 - OK
' Try to retrieve more information about the network error
If Not wex.Response Is Nothing Then
Dim errorResponse As HttpWebResponse = Nothing
Try
errorResponse = DirectCast(wex.Response, HttpWebResponse)
MsgBox("The server returned '{0}' with the status code {1} ({2 })." & errorResponse.StatusDescription & " , " & errorResponse.StatusCode & " , " & errorResponse.StatusCode)
Finally
If Not errorResponse Is Nothing Then errorResponse.Close()
End Try
End If
Finally
If Not Response Is Nothing Then Response.Close()
End Try
elevationvalue = sbSource.ToString
modified on Wednesday, February 25, 2009 10:31 AM
|
|
|
|
|
|
I'm very sorry. You seem to have confused CodeProject.com with RentACoder.com
|
|
|
|
|
You have got to be one of the most clueless people here, and that is really saying something. First you create an article to ask a question, then you repeat that ie another article and now you are asking for a rentacoder.
Can you find the link for rentacoder or do you need help with that too!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How to place the text at cursor position in vb.net textbox
|
|
|
|
|
Look into the TextBox's SelectionStart property.
|
|
|
|
|
|
Hello my name is Jordan
MY problem if how can I save my playlist even If I shutdown the computer?
my sample code is :
'this sub is used to add url type playlist in the playlistbox
Private Sub FileOpener_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles FileOpener.FileOk
'filenames is used because we want to get the path or url address of file choosen
'in order to play the choosen file by th visual player
For Each track As String In FileOpener.FileNames
'add the file choosen to the playlist
PlaylistListUrlBox.Items.Add(track)
Next
'change the value of titleLabel in the file choosen open by safe file names
'safe file name means that it will only get the file name not the path of the file
TitleLabel.Text = FileOpener.SafeFileName
End Sub
The playlist I created is the address or location of the file choosen
Thanks and more power codeproject.com for the help
|
|
|
|
|
Handle the form's Closing event and write the data you need to save to a file from there.
|
|
|
|
|
Hi,
i have a function on in a module.
i also have a button on a sheet.
how do i trigger the function when i hit the "Enter" key on the keyboard.
i tried to record a macro but this doesn't work.
any ideas?
thanks in advance.
Anoop
|
|
|
|
|
The worksheet and workbook objects don't have a KeyDown or KeyPress event, so the only way to tell would be if the sheet is set to recalcuate itself (which it normally does by default) and you handle the Calculate event.
|
|
|
|
|
Hello, My name is Jordan
I am using vb 2008 express edition
if someone could help I am really thankful but if not guess I have to
make my self push to what I can't do
My problem is if
1. How can I make save ms access database by using vb 2008?
2. How can I link a data base file to display by using a file in the database also?
Thanks and more power codeporject.com
|
|
|
|