IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Experience IT
In a World of Technology, People Make the Difference.
  1. Home
  2. Technology
  3. Program Language
  4. C#
  5. This article

Checks if the remote file exists

2020-11-19 279 Views 0 Like 0 Comments

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; }
}

 291 total views,  5 views today

error
fb-share-icon
Tweet
fb-share-icon
IT Team
Author: IT Team

Tags: None
Last updated:2020-11-19

IT Team

This person is lazy and left nothing

Like

Comments

Cancel reply
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
Fixing Kratos theme multi-language issue How to automatically translate a website to any language Controling Category List on Sidebar Widget Restoring the Links Manager Adding reCaptcha for user forms in WordPress Scheduling Background Job in WordPress
2021 最新 DotNet 资源大全
Tracking referral ID for registered user in WordPress Changing DataTable cell width Feature image is repeating on post Reporting notes Wordpress + polylang - Globalization Automation report and validating
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • Digital Marketing
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

THEME KRATOS MADE BY VTROIS