Get Created date from local path via asp.net - c#

Please help to get file created date from asp.net ascx (ex.)
This is load image from page
Bitmap originalBitmap = new Bitmap(flpContainer.FileContent);
// how to get image **created date** via uploading from local machine (not uploading date)
I want try with FileInfo class, but for asp.net it not work to read a local file properities.
I have functional in web : User upload images from local file system to our application and I want take image created data in File system. I can create new column for created_date in DB, but how I can take created Date image from FS (not created uploading date just created date in local machine via asp.net).

#Eldar, that information is actually lost as it is not transmitted as part of the file upload. You can only get information about the file name. You could request your users to supply a create date as part of the upload or you could set it yourself as part of the upload process to DateTime.Now.
Sorry I couldn't be of more help

Related

C# ASP.NET Retrieving file address in string

I am building a method that will build an XLS file and uploading it on user's computer.
I am using this guide:
http://csharp.net-informations.com/excel/csharp-create-excel.htm
So code that will define my destination address is:
xlWorkBook.SaveAs("C:\\Something\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal);
Now it is default, but i want to allow user to define it by him self, so as far as i understand, i need an html field, which will open common "browse window" and save file path to string, which will be later used in xlWorkBook.SaveAs function. I have read a bit about FileUpload, but i don't really sure that it is what i am looking for.
The code that you have there will save the file on the web server itself, not on the user's computer. You'll need to stream the file down to the user via the browser, and then they will be able to choose where to save it.
You could save the file on the server and then stream it to the user using Response.WriteFile, or you could stream it from memory if you don't want to keep a copy of the file on the server.
This code will create a file on the server, not on the users/clients computer. If you want the user to be able to download the file to his/her computer and select the location where the file is stored, you need to create a file (.aspx file or controller method, depending on wether you are using webforms or MVC) and have it stream the file to the user's browser. The browser will then take care of displaying the "Save as" dialog where the user can select the destination location.

Get last modified date of a remote file

I have an app with which at startup it downloads a file from a remote location (through the net) and parses it's contents.
I am trying to speed up the process of startup as the bigger the file gets the slower the app starts.
As a way to speed up the process I thought of getting the last modified date of the file and if it is newer from the file on the user's pc then and only then download it.
I have found many ways to do it online but none of them are in C# (for windows store apps). Does anybody here know of a way of doing this without the need to download the file? If I am to download the file then the process is sped up at all.
My C# code for downloading the file currently is this
const string fileLocation = "link to dropbox";
var uri = new Uri(fileLocation);
var downloader = new BackgroundDownloader();
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("feedlist.txt",CreationCollisionOption.ReplaceExisting);
DownloadOperation download = downloader.CreateDownload(uri, file);
await download.StartAsync();
If it helps the file is stored in dropbox but if any of you guys have a suggestion for another free file hosting service I am open to suggestions
Generally, you can check the file time by sending HEAD request and parsing/looking HTTP header response for a Last-Modified filed. The remote server should support it and DropBox does not support this feature for direct links (only via API). But DropBox have another feature, the headers have the etag field. You should store it and check in the next request. If it changed - the file has been changed too. You can use this tool to check the remote file headers.

How to upload/Save photo to a http server using webservice?

I have to upload photo to a folder in a HTTP server from a window application using web-service.I have converted the photo into stream and passed to a web-service but how can i save it to a location (eg: http:/siteaddress/images/photos/) in the server.
the web service has to get the stream from the client and convert it back to file in the location you mentioned.
string destinationFolder = Server.MapPath("/images/photos");
then assuming that in your web method you get a stream and a string with a unique file name, you save the steam into such file name in the destinationFolder above.
if you want to generate a unique name you can create a GUID, I'm sure you will need also the id of the user or so, just to save somewhere who has uploaded this photo.
the destination folder like images/photos should be taken from an app setting in the web.config or from the database, not hardcoded as in my example.

save and retrieve values within web app

I have a simple web app built in asp.net webforms c#
where and how would be the best way to save info from the code behind?
(and also retrieve that info)
eg all i want to save is a dateTime. and a flag set to True or False.
and be able to access them in the code behind.
Im not using a db for this web app.
Edit: and can't really use session variables for this purpose.
thanks
If you have to save data for an arbitrary period of time, then you need to store it in a database.
If you need to read the saved variable after a lengthy period of time, you should store it in a local file or a database.
You can create a file using a FileStream object and then write your value to the file.
To get a path where your application has sufficient rights to write a file, use Server.MapPath.
Note : If possible, and if the data you store should not be available to users, you should configure your IIS WebSite to forbid him to serve this file to clients.
Use Application variable like Application["thedate"] = date; and you can get back as date = Application["thedate"].
The date will be saved untill app pool restarts (which also happens when IIS or system restarts).
For a more longer time, save in an xml file on the disk (Use XMLReader and XMLWriter for this purpose).
If this is per user info you could use either browser cookie or viewstate.
Use the Session object:
Session["thedate"] = date;
DateTime date = (DateTime)Session["thedate"];

Mapping A Filename To Paths on A Server Asp.net

I have a problem with my code. My code is using the fileupload control to browse for a filename when you add a filename it processes it and the code runs fine on when it lives on local host, but when I put the code on our prodution server it cannot find the filenames listed by user.
For example if I use the upload control to browse to
B:\MIS\CH Intive\RPTTOFL_3.csv and the code lives on my localhost which know what that file path means it works, but if the code is moved to a production server it may or maynot know what B:/ is or B:/ maybe mapped to something else.
Even if I am browsing to a file on my C drive it will work on if the code is on the machine that the C drive is on, but it will not work if the code is on another machine because obviously that file wouldnt be on that C drive.
Private Function CSV2DataTable(ByVal filename As String) As DataTable
Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(filename)
MyReader.TextFieldType = FileIO.FieldType.Delimited
.
.
.
What can I do in asp.net to make the filename work correctly?
Ok lets say I get the filename and save it as so
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
now I want to pass the filename to the function above for processing. Do I pass Server.MapPath("~/") + filename as the filename? Also when I am done what do I do to delete the file from the server?
It seems that you are mixing the client and server locations of the file. Before reading the uploaded file, the server-side code must save it on the server (client-side file location is mostly irrelevant at this point). From VS help on FileUpload class: "The code that you write to save the specified file should call the SaveAs method, which saves the contents of a file to a specified path on the server." The online help topic on FileUpload control has enough information (with examples) to achieve what you need.

Categories