IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
C#
C#

Checks if the remote file exists

Language: C# /// <summary>Get remote file information</summary> /// <param name="url">The URL of the remote file</param> /// <returns>RemoteFile if the remote file exists, or null</returns> public static RemoteFile RemoteFileInfo(string url) { RemoteFile file = new RemoteFile(); try { var request = WebRequest.Create(url); request.Method = "HEAD"; using (var response = request.GetResponse() as HttpWebResponse) { file.LastModified = response.LastModified; file.Size = response.ContentLength; file.StatusCode = response.StatusCode; file.ContentType = response.ContentType; file.ContentEncoding = response.ContentEncoding; } } catch(Exception e) { return null; } return file; } public class RemoteFile { public DateTime LastModified { get; set; } public long Size { get; set; } public HttpStatusCode StatusCode { get; set; } public string ContentType { get; set; } public string ContentEncoding { get; set; } }  1,661 total views

2020-11-19 0 Comments 515 Views 1 Like IT Team Read more
Chinese (Simplified) Chinese (Simplified) Chinese (Traditional) Chinese (Traditional) English English French French German German Japanese Japanese Korean Korean Russian Russian
Newest Hotspots Random
Newest Hotspots Random
All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions How to block bad bots in Appache server Add ALT attribute to Social Media Icon Change Event Calendar Title
All Unicode Chars
Embeding PDF file on a wp page WordPress EventCalendar visibility Temporary tables lifetime Customize theme CityZen Controlling sidebar hide/show on post Python Data Visualization Practise
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

This site is supported by Hostlike.com