IT Blog

  • Blog
  • 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. 首页
  2. Technology
  3. Program Language
  4. C#
  5. 正文

Checks if the remote file exists

2020年11月19日 195点热度 0人点赞 0条评论
Loading...

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; }
}
IT Team
Author: IT Team

Loading...
标签: 暂无
最后更新:2020年11月19日

IT Team

stay absorbed stay excellent

点赞

文章评论

取消回复
最新 热点 随机
最新 热点 随机
Generating Test Data with SQL Scripts Remote connection to MySQL on SiteGround Hide author information from WordPress How to do some trick to improve WordPress performance Recovering user role in WordPress Sending email using gmail SMTP
How to do some trick to improve WordPress performanceRemote connection to MySQL on SiteGroundGenerating Test Data with SQL ScriptsRecovering user role in WordPressHide author information from WordPress
用设计模式降低循环复杂性 Develop undo feature with trigger Show any data in DataTables in WordPress Sending mail from SSIS Generate city list for UPDATE statement in MySQL Python - Crawling images from json file
Categories
  • AdSense
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • Digital Marketing
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 20203-2021 Hostlike.com. ALL RIGHTS RESERVED.