472,374 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

System.Net.WebClient DownloadString File Size Issue

I am using PowerShell to download an XML file into a string using the
DownloadString(URI) method of System.Net.WebClient object. Sample
commands below:

$Result = $Null;
$WebClient = new-object System.Net.WebClient;
$WebClient.Encoding = [System.Text.Encoding]::Default;
$WebClient.Proxy = [System.Net.WebRequest]::DefaultWebProxy;
$WebClient.Proxy.Credentials =
[System.Net.CredentialCache]::DefaultCredentials;
$Result = $WebClient.DownloadString("http://www.thomas-krause.de/
weblogs/elcaroop/rss.xml");
$Result | out-file "D:\DownloadString.xml";

This works as expected and the content of the original file seems to
be exactly the same as the downloaded file. The issue I am having is
that the file retrieved using $WebClient.DownloadString is
approximately twice the size of the original file (downloaded by doing
a "Save Target As..." when right clicking on the URL).

Can anyone explain why this is happening?
I have tried changing the System.Text.Encoding setting to all 7 types
that are available, some of them then give the correct file size that
I expect but the data is modified, while others give me the data that
I expect but not the file size that I expect.

The $webClient.DownloadFile("http://www.thomas-krause.de/weblogs/
elcaroop/rss.xml", "D:\DownloadedFile.xml");
method works fine for me and I get the exact data and file size as the
original but I would perfer to use DownloadString to avoid working
with local copies of the file.

Mike

May 2 '07 #1
1 12235
Try the DownloadData method and convert the resulting byte array to a string
using (e.g) System.Text.Encoding.UTF8.GetString
and see if that doesn't help. You supply the desired encoding.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Mike" wrote:
I am using PowerShell to download an XML file into a string using the
DownloadString(URI) method of System.Net.WebClient object. Sample
commands below:

$Result = $Null;
$WebClient = new-object System.Net.WebClient;
$WebClient.Encoding = [System.Text.Encoding]::Default;
$WebClient.Proxy = [System.Net.WebRequest]::DefaultWebProxy;
$WebClient.Proxy.Credentials =
[System.Net.CredentialCache]::DefaultCredentials;
$Result = $WebClient.DownloadString("http://www.thomas-krause.de/
weblogs/elcaroop/rss.xml");
$Result | out-file "D:\DownloadString.xml";

This works as expected and the content of the original file seems to
be exactly the same as the downloaded file. The issue I am having is
that the file retrieved using $WebClient.DownloadString is
approximately twice the size of the original file (downloaded by doing
a "Save Target As..." when right clicking on the URL).

Can anyone explain why this is happening?
I have tried changing the System.Text.Encoding setting to all 7 types
that are available, some of them then give the correct file size that
I expect but the data is modified, while others give me the data that
I expect but not the file size that I expect.

The $webClient.DownloadFile("http://www.thomas-krause.de/weblogs/
elcaroop/rss.xml", "D:\DownloadedFile.xml");
method works fine for me and I get the exact data and file size as the
original but I would perfer to use DownloadString to avoid working
with local copies of the file.

Mike

May 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: ptass | last post by:
Hi I've installed win2k3 sp1 on a machine where an openRead on any given file was previously working. After installation, I get a webException as follows... ..message "An exception occurred...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
6
by: | last post by:
I've written a very small ASP.NET page to scrape thousands of pages of content based on database IDs. It loops through a dataset to get the IDs. It worked well in testing but now I am getting an...
2
by: Tosco | last post by:
I read many examples with NetworkCredential and WebClient, but no one with a real http address. They all work in theory, but I wasn't able to use them in the real world. The following code should...
8
by: MaxMax | last post by:
Is it possible to tell to the WebClient to use an "automatic" encoding when doing DownloadString? The encoding of the connection is written in the header, so the WebClient should be able to sense...
0
by: larsergud | last post by:
Hi all, This code genearates a error saying "could not connect to remote server", but only by the webclient call inside the loop, eventhough it's the exact same calls? any suggestions? ...
2
by: MichaelSchoeler | last post by:
Hi, I'm having problems with the WebClient class regarding UTF-8 encoded data. When I access a specific webservice directly I can see the data arrives in corretly formatted UTF-8. But when I...
6
by: =?Utf-8?B?YmlsbCB0aWU=?= | last post by:
An authoritative source claims out-of-the-box asynchronous "WebClient's implementation is flawed" in .Net 3.0. Was it fixed in .Net 3.5 or .Net 3.5 SP1? Thank you.
0
by: alex21 | last post by:
I want to display the progress of the WebClient.DownloadString() method using a progress bar? Anyone know? Thanks Alex.
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.