Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using FTP and clearing out memory
Message
From
26/04/2013 06:18:21
 
 
To
26/04/2013 03:54:41
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:
01571897
Message ID:
01571955
Views:
38
>>>>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?
>
>
>More readable - it is - I like to keep the indent
>
>			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());
>
>
>But I like to put the braces - sometimes - when not really needed. It's like an if/foreach - to avoid surprises when I need to add a statement

I think I agree. Don't remember actually seeing this construct used anywhere.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform