Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to find the size of xml before downloading the file on to the local desktop after clicking the button in the browser this size of the xml file should be dispalyed in pop up or in a label just for displaying the size to user using asp .net c#. How can i do this

What I have tried:

I am new to xml concept can anybody help me out
Posted
Updated 16-Jan-18 14:35pm
Comments
Richard MacCutchan 22-Dec-17 6:33am    
This has nothing to do with XML. The size of the file can be found by C# code in the backend before the download starts.
kav@94 22-Dec-17 7:08am    
how can i do it at the backend could you illustrate with an example
Richard MacCutchan 22-Dec-17 9:51am    
OriginalGriff already showed you how to find the size of a file. XML files are just files, nothing special about them.

The problem is that is a browser function, not anything that C# can do - unless the file is being downloaded from your website in which case it's trivial: Get the FileInfo, and look at the Length property:
long length = new System.IO.FileInfo(path).Length;


But in a browser? You can't control what the user is looking at, and you can't check in advance what size it's going to be. It's possible that if you write a browser extension you may be able to do this, but that won't be in C# - and you'd have to write a new extension of each browser (and hope that the client upgraded from the pre-Anniversary Update Edge which didn't support extensions at all)
 
Share this answer
 
If you're downloading it from the web, you can use HEAD instead of get to get the XML files Content-Length as one of the http headers. The following, or similar, should work if you're using webrequest to fetch. This won't send the XML file, just the response headers.



long len=0;
WebRequest req = WebRequest.Create (url);
req.Method = "HEAD";
using(WebResponse res=req.GetResponse()) {

len=res.ContentLength;

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900