Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using FTP and clearing out memory
Message
De
26/04/2013 03:43:30
 
 
À
26/04/2013 02:47:09
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01571897
Message ID:
01571951
Vues:
30
>>BTW, if I do this triple Using cascading, I end up with this:
>>
>>"Overload resolution failed because no accessible 'New' can be called without a narrowing conversion"
>>
>>This is at the design time on the loStreamReader Using line.
>
>I've added some static properties (uri, user, password) to test this
>
>I have no problem with the triple using
>
>I think we need some code of yours - the error you are getting is not related to Using - more a problem of type/casting
>
>(update : forget the out-the-loop part for the Uri - I now see it contains the remote directory )
>
>
>
>		public static void Main()
>		{
>			StringBuilder loStringBuilder = new StringBuilder();
>
>			// this part outside the loop - even at class level if possible
>
>			NetworkCredential credentials = new System.Net.NetworkCredential(cUsername, cPassword);
>			// end part
>
>			Uri uri = new Uri(lcURI);
>
>			// FTP setup
>			var loFtpWebRequest = System.Net.FtpWebRequest.Create(uri);
>			loFtpWebRequest.Credentials = credentials;
>			loFtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails;
>
>			// If we use FTP/SSL  (AUTH SSL)
>			// If ( nNoFTPProtocol == 2) 
>			//     loFtpWebRequest.EnableSsl = true;
>            
>
>			using ( var loFtpWebResponse = loFtpWebRequest.GetResponse() )
>			{
>				using ( var s = loFtpWebResponse.GetResponseStream())
>				{
>					using( var loStreamReader = new StreamReader(s) )
>					{
>						// Load the files into the string builder
>						loStringBuilder.Append(loStreamReader.ReadToEnd());
>					}
>				}
>			}
>			Console.WriteLine("{0}", loStringBuilder.ToString());
>			Console.ReadLine();
>
>		}
>
>
Not particularly relevant but the above reminded me that you can do this:
using (var loFtpWebResponse = loFtpWebRequest.GetResponse())
using (var s = loFtpWebResponse.GetResponseStream())
using (var loStreamReader = new StreamReader(s))
            {
                // Load the files into the string builder
                loStringBuilder.Append(loStreamReader.ReadToEnd());
            }
Don't know if I regard it as more readable or not?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform