0

C# を使用してファイルのメタ データを検索する必要があります。使用するファイルはサード パーティのサイトに保存されています。そのサーバーからファイルをダウンロードできますが、ダウンロードしたファイルの元のメタデータを取得できません。c# を使用してこれを達成する方法。以下は私のコードです。

string FilePath = AppDomain.CurrentDomain.BaseDirectory + @"Downloads\";
            string Url = txtUrl.Text.Trim();
            Uri _Url = new Uri(Url);
            System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(_Url);
            request.Timeout = Timeout.Infinite;
            System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
            response.Close();
            if (response.ContentType != "text/html; charset=UTF-8")
            {
                string FileSize = response.Headers.Get("Content-Length");
                int lastindex = Url.LastIndexOf("/");
                string TempUrlName = Url.Substring(lastindex + 1, Url.Length - (lastindex + 1));

                WebClient oWebClient = new WebClient();
                oWebClient.DownloadFile(txtUrl.Text.Trim(), FilePath + @"\" + TempUrlName);
                if (File.Exists(FilePath + @"\" + TempUrlName))
                {
                    FileInfo oInfo = new FileInfo(FilePath + @"\" + TempUrlName);
                    DateTime time = oInfo.CreationTime;
                    time = oInfo.LastAccessTime;
                    time = oInfo.LastWriteTime;
                }
            }

ファイルをローカルに保存した後でのみ、ファイルサイズ、作成時間、最終アクセス時間、最終書き込み時間を取得できます。しかし、ファイルがC#を使用してサーバーにある場合、ファイルのメタデータ情報が必要です。

ありがとう

4

1 に答える 1