473,574 Members | 18,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Net.WebC lient DownloadString File Size Issue

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

$Result = $Null;
$WebClient = new-object System.Net.WebC lient;
$WebClient.Enco ding = [System.Text.Enc oding]::Default;
$WebClient.Prox y = [System.Net.WebR equest]::DefaultWebPro xy;
$WebClient.Prox y.Credentials =
[System.Net.Cred entialCache]::DefaultCreden tials;
$Result = $WebClient.Down loadString("htt p://www.thomas-krause.de/
weblogs/elcaroop/rss.xml");
$Result | out-file "D:\DownloadStr ing.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.Down loadString 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.Enc oding 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.Down loadFile("http://www.thomas-krause.de/weblogs/
elcaroop/rss.xml", "D:\DownloadedF ile.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 12476
Try the DownloadData method and convert the resulting byte array to a string
using (e.g) System.Text.Enc oding.UTF8.GetS tring
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.WebC lient object. Sample
commands below:

$Result = $Null;
$WebClient = new-object System.Net.WebC lient;
$WebClient.Enco ding = [System.Text.Enc oding]::Default;
$WebClient.Prox y = [System.Net.WebR equest]::DefaultWebPro xy;
$WebClient.Prox y.Credentials =
[System.Net.Cred entialCache]::DefaultCreden tials;
$Result = $WebClient.Down loadString("htt p://www.thomas-krause.de/
weblogs/elcaroop/rss.xml");
$Result | out-file "D:\DownloadStr ing.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.Down loadString 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.Enc oding 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.Down loadFile("http://www.thomas-krause.de/weblogs/
elcaroop/rss.xml", "D:\DownloadedF ile.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
942
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 during a webclient request" .._Hresult = "-2146233079" .._COMPlusExceptionCode ="-532459699" Sorry I don't have the whole error, but this seems to...
6
13274
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 = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileID.ToString() + ".pdf");
6
3542
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 annoying 403 error that causes the script to abort halfway through my download. I am wondering if there is a way in ASP.NET to have my code ignore...
2
3940
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 access an ebay page. There is no redirection involved in TestPage. If you have an ebay account you can try it in 1 minute. What's wrong with...
8
24509
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 it, but I wasn't able to find the option. I can only use a fixed Encoding (UTF8 for example) and hope the site use it. --- bye
0
1337
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? string newChat; string oldChat = webClient1.DownloadString("http://www.zzzzzzz.com"); while (1 < 2) {
2
10149
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 try to pull data from the same webservice url through the WebClient class I get partly garbled UTF-8 data in return. Only some UTF-8 chars (double byte...
6
2672
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
1173
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
7817
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8081
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8258
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7833
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8119
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6482
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2254
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.