473,382 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

size of file located at url

My web app needs to determine the file size in bytes for image file urls
stored in db. Does .NET provide a method that can determine the file size in
bytes ?
Sep 21 '06 #1
1 4170
John,

Not really. It completely depends on the protocol that the URL
represents. If the protocol is http, or https, then you can do this easily.

You can issue a HEAD request to an HTTP server resource and (assuming it
implements the HTTP 1.1 protocol) it should return a Content-Length header
which you can then use as the size of the file. However, this will only
work for static resources, as dynamically generated pages don't typically
populate this header.

Now, to do this in .NET, you can create a WebRequest/WebResponse for the
particular protocol using the static Create method on the WebRequest class.
Then, you can issue a call to GetResponse, and then access the ContentLength
property on the response that is returned to you.

If you are working with HTTP resources only, then you can do this:

// Create the request.
WebRequest request = WebRequest.Create(url);

// Set the method to HEAD.
request.Method = "HEAD";

// Get the response.
using (WebResponse response = request.GetResponse())
{
// Get the length.
long length = response.ContentLength;
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"John A Grandy" <johnagrandy-at-yahoo-dot-comwrote in message
news:uw**************@TK2MSFTNGP02.phx.gbl...
My web app needs to determine the file size in bytes for image file urls
stored in db. Does .NET provide a method that can determine the file size
in bytes ?

Sep 21 '06 #2

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

Similar topics

23
by: BobK | last post by:
Hello Everyone, I am updating the CSS for my site but want new and original page to appear the same. My original CSS permits small increments of zooming (ctrl/mouse wheel) so that you get...
8
by: Pocket Rocket | last post by:
I am developing an application using Windows forms, C# and Visual Studio.Net. The executable size remains the same whether I built the debug or release version. Is it normal? Am I missing...
0
by: JollyK | last post by:
Looking for opinion on code size for presention tier asp.net application. I have created a user-control that has a fairly complex datagrid which includes localization, custom paging, sorting,...
1
by: Mark | last post by:
How can I get size of file on http resource? For example I want to get the total size of the file which is located on http://mysite.com/myfile.zip.
4
by: JollyK | last post by:
Hello everyone... I have created a user-control that has a fairly complex datagrid (with template columns) which includes localization, custom paging, sorting, filtering, searching, caching,...
2
by: Charlie | last post by:
Hi: I have chosen to use Jet 4.0 db engine on an e-commerce site because client wants to save on hosting costs and doesn't expect a lot of traffic. In the past I have always used SQL Server and...
6
by: sambuela | last post by:
How can I write message to the file located in the wwwroot directory? It seems that IIS protect these files. Let make me cannot do the I/O writing sucessfully. I try to open file's write...
7
by: serge calderara | last post by:
Dear all, I am building an ASP 1.1 application based on a n-Tier architecture. I have my datalayer class that need to read the connection string of my sql server database from a configuration...
11
by: rawu | last post by:
hi , all . I got a question about creating indexes in db2 . a table has 44236333 rows an index planed to be build include 2 field ( 6 byte ) accordding to db2 document temporary...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.