Is it possible to get file properties of a web file. ie: PDF file and get the date and time the PDF file was modified. Thanks.
You're probably looking for the HttpWebResponse.LastModified property.
No, you can't. It's not a file, it's a resource.
When you request it from the server you get a response back. In this case the server uses a file as source for the resource, but it could just as well be something that is just created on the fly. You only get the information that the server chooses to put in the HTML header.
You might however be able to get some more information if the server returns directory information. Then you could request the folder and get a listing back, from which you could parse some information. Note however that it's not certain that the server actually uses the files when you request something from the directory, it could still return something completely different. Also, the directory listing is also a resource, so there is no guarantee that it's relevant either.
Related
I'm working on a continuing API project. The current issue at hand is to be able to download my data from the AtTask server in precisely the folder structure they exist in on the AtTask servers. I've got the folder creation working nicely; the data types between Document, Document Folder and Document Version seem to be pretty clear. I am a little disillusioned about the fact that extension isn't in the document object (that I have to refer to the document VERSION for that)... but I can see some of the reason for that from a design perspective.
The issue I'm running into now is that I need to get the file content. I originally through from the API documentation that I'd be able to get to the file contents the same way as the documentation recommends uploading it -- through the handle. Unfortunately, neither document nor docv seem to support me accessing the handle except to write a new file.
So that leaves me the "download URL" as the remaining option. If I build the UI strings from the API calls using my browser, I get a URL with https://attaskURL/document/download?ID=xxxx (and can also get the versionID and such). If I paste the url into the browser where I'm logged in to the user interface of AtTask, it works fine and I can download the file. If, instead, I use my C# code to do so, I get the login page returned as a stream for me to download instead of my actual file because I'm not authenicated. I've tried creating a network credential and attaching it to the request with the username and password, but to no avail.
I imagine there's a couple ways to solve this problem -- the easy one being finding a way to "log in" to the download site through code (which doesn't seem to be the usual network credential object in C#) OR find a way to access the file contents through the API.
Appreciate your thoughts!
It looks like you can use the download URL if you put a session id in the URL. The details on getting a session id are here (basically just call login and a session id is returned in JSON):
http://developers.attask.com/api-docs/#Authentication
Then cram it on the end of your document download URL:
https://yourcompany.attask-ondemand.com/document/download?ID=xxxx&sessionID=abc1234
I've given this a quick test and I'm able to access a document.
You can use the downloadURL and a sessionID IF you are not using SAML authentication.
I have tried it both ways and using SAML will redirect you to the login page.
I am trying to read the contents of a JSON file sitting in my github pages repository.
I can navigate and see the file contents in my browser if I specify the url.
If I use the code here:
http://www.codeproject.com/Tips/397574/Use-Csharp-to-get-JSON-Data-from-the-Web-and-Map-i?msg=4615047#xx4615047xx
It claims to "just work", but it doesn't.
All I get back is:
<html><frameset><frame src="URL-TO-JSON-FILE"></frameset></html>
How am I supposed to read the json file and get its contents back as a string. I am using c#?
Once I get the JSON string back I can do the processing I need to do in c#.
EDIT:
According to rawgithub.com those types of urls are not to be used for production. I need this for production. How do production website read remote JSON files that are located on a webserver?
Thank you
Sometimes in github, if you wish to use code from a repository, you must change the url to raw.github.com/ or click on the raw button and use this url.
i want to read web directory files.
when i use this code.
string[] files;
string webfilepath = "http://www.anydomain.com/templates/images";
files = Directory.GetFiles(webfilepath, #"*.*", SearchOption.TopDirectoryOnly);
code shows error url format not support.is there any other way to read web directory.
thanks in advance.
is there any other way to read web directory
No. HTTP has no "directory index" you can retrieve, unless the server (or software running on it) generates it itself, for example Apache's Options +Indexes configuration. But then that index is generated in HTML, which you'll have to parse to get the full filename.
you cant do this in a generic way. Because its up to the web server how it dump the directory content on to client if it does that at all.
First you need to make sure that your server send out the content using some protocol. then you can use HttpWebRequest to send a HTTP request and get the result. you will have to do your own parsing on the result at the end of the day.
You are trying to pass url to Directory.GetFiles instead of passing physical path of folder, You can use Server.MapPath to get the physical path of url if it is accessible i.e. the code for accessing folder is running on the machine url is point to. If url is on different machine then you can not use Directory.GetFiles.
I have a scenario in my mind .. I need validations/suggestions from Stack over flow !! :)
There is a (remote)apache server hosting this URL "http://someserver.com/logs/log.txt:4041" .When i hit this URL in IE it opens a page containing log.txt in a file-folder-directory structure (after authentication).
Is there any way to get the attributes of the log.txt (attributes what i mean is file creation date,file modification date,file size etc..).
What I am planning to do is to write a code in C#.net(in the client) using system.IO namespace and using the fileinfo class and use
FileInfo fi = new FileInfo(pathname);
fi.CreationTime.toString() to retrieve the file creation time.
This is successful for files that exists in local directories in my hard drive!! .
Is it possible to use the same code for retrieving the information about the file that exists in the server that is accessed using the URL "http://someserver.com/logs/log.txt:4041" ?? if yes should i give the URL in my pathename ?
Take it for granted that i have access to the server by authentication..
You can try to inspect the data in WebResponse.Headers. The web server will send some date/time information of the file with the response. This may however not be what you expect depending on the web server you're calling and whether the page you are loading is a script or a file on disk. Settings of the web server will also influence the details returned.
You will not be able to use FileInfo method for items retrieved from http. However if the directory that the file that you are getting served to you is accessible from a share of from samba you could use this method.
How can I programmatically tell if a binary file on a website (e.g. image) has changed without downloading it? Is there a way using HTTP methods (in C# in this case) to check prior to fully downloading it?
Really, you want to look for the Last-Modified header after issuing a HEAD request (rather than a GET). I wrote some code to get the HEAD via WebClient here.
You can check that whether the file is changed or not by requesting with HEAD.
Then, returned response header may include Last-Modified, or ETag if the web server support.
You can do a HEAD request and check the last-modified datetime value, as well as the content-length.