---
title: "C# Read file info from URL"  
description: "C# Read file info from URL"  
author: "Anonymous User"  
published: 2014-12-02  
updated: 2019-04-18  
canonical: https://www.mindstick.com/forum/12731/c-sharp-read-file-info-from-url  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# C# Read file info from URL

In my [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [MVC application](https://www.mindstick.com/forum/12932/how-to-consume-webservices-from-asp-dot-net-mvc-application) I'm [reading](https://www.mindstick.com/articles/126273/books-commonly-found-on-college-reading-lists) an [external](https://www.mindstick.com/articles/12810/how-to-connect-tablet-to-external-monitor-or-flat-screen-tv-using-computer-adapters) file from URL and saving it into a [directory](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp) on my server. I do this in a loop for every few seconds to have actual data if the file was modified.

What I need is to recognize that the LastWrittenTime of the file accessed via the URL is different from file [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) downloaded to the server. I cannot use FileInfo class because "URI [formats](https://www.mindstick.com/forum/160705/explain-the-concept-of-datetime-formats-in-c-sharp) are not supported".

So how do I get the last written time of the file from the URL without needing to [download](https://www.mindstick.com/articles/188403/website-to-download-photos-from-instagram) the full file for every loop?

## Replies

### Reply by Anonymous User

Assuming your HTTP Server allows this.

```
System.Net.WebRequest req = System.Net.HttpWebRequest.Create("http:\\your\url.ext");req.Method = "HEAD";using (System.Net.WebResponse resp = req.GetResponse()){    DateTime LastModified;    if(DateTime.TryParse(resp.Headers.Get("Last-Modified"), out LastModified))    {         //Check if date is good and then go to full download method.    }}
```

When this method doesn't work because the server doesn't allow it. Then the only way of doing this is by fully downloading the file.


---

Original Source: https://www.mindstick.com/forum/12731/c-sharp-read-file-info-from-url

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
