Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
More on Using End Using
Message
From
03/05/2013 11:44:28
 
 
To
03/05/2013 11:16:08
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01572620
Message ID:
01572626
Views:
64
This message has been marked as the solution to the initial question of the thread.
>Recently, we fine tuned some objects and memory related issues in a FTP class I have.
>
>In the DeleteFile() method, I have this:
>
>
>                            ' FTP setup
>                            loFtpWebRequest = System.Net.FtpWebRequest.Create(New Uri(lcURI))
>                            loFtpWebRequest.Credentials = New System.Net.NetworkCredential(cUsername, cPassword)
>                            loFtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
>
>                            ' If we use FTP/SSL  (AUTH SSL)
>                            If nNoFTPProtocol = 2 Then
>                                loFtpWebRequest.EnableSsl = True
>                            End If
>
>                            ' Delete the file
>                            loFtpWebRequest.GetResponse().Close()
>
>
>I have been wondering if I could implement some Using End Using syntax for this part as well. The Close() syntax of the loFtpWebRequest.GetReponse() is not easy to negotiate with if I would try to encapsulate that into such syntax. Anyone would have an idea on what kind of syntax I could use?
>
>The closest I could have right now is this:




As far as I know - The Dispose() will call the Close() -- hence you needn't call Close()
>
>                            ' FTP setup
>                            loFtpWebRequest = System.Net.FtpWebRequest.Create(New Uri(lcURI))
>                            loFtpWebRequest.Credentials = New System.Net.NetworkCredential(cUsername, cPassword)
>                            loFtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
>
>                            ' If we use FTP/SSL  (AUTH SSL)
>                            If nNoFTPProtocol = 2 Then
>                                loFtpWebRequest.EnableSsl = True
>                            End If
>
>                            Using loFtpWebResponse = loFtpWebRequest.GetResponse()
>
>                                ' Delete the file
>                                loFtpWebResponse().Close()
>
>                            End Using
>
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform