Fetching the username who last modified or created the file - c#

Is it possible to get the name of the user who just pasted a file into a folder?
A brief overview of what I am trying to do:
My application keeps watch on a folder for new files every 10 minutes. If it finds any new file it will upload that file via FTP to a specified location.
I would like to know who dropped this file into the folder. Please note that this could be different from the person who created the file.
Thanks
Nishant

The identity of the user modifying a file is not stored in the NTFS Change Journal, but you could use auditing of file access as suggested in this related post.

Related

TelegramApi C# GetFile

I don't know how to specify the path to the directory where I need to save the file.
Please tell me how can I save the file to the desired directory received from the user and also create a separate folder for this user in the directory?

Generate id for files based on file content

I am using a upload mechanism for users to upload files and the user is suppose to receive 3 different file extracted from the uploaded one in an group which is identified by the uploaded file name.
I am trying to map the output files to it's parent file.
How can generate something unique that can be linked to the files so that they are easily associated to its group.
I am using C# and SQl Server Filestream to store the files in database.
The limitation that i am facing is that I cannot rename the file provided by user.
Can someone help me out here?

How to extract name/data from database and use it as my folder name which is created dynamically in asp.net c# using server.MapPath()?

I have used AjaxFileUpload to upload multiple image files. Now i want to store the uploaded images inside rootfolder>subfolder.
The rootfolder is in the name of the user.
The rootfolder is created dynamically by taking the session of the user who has logged in
Like this:
string username = Session["username"].ToString();
I am able to create this folder and save images in it. but i want to save it in subfolder.
the subfolder is also created dynamically but this time i have to take the value(id) from the database and name the folder by that id name. (this is so that i can refer to the database)
I know how to create a new folder using Server.MapPath();
Here is the code for it in brief
using System.IO
if (Directory.Exists(Server.MapPath(uploadPath))) return;
else Directory.CreateDirectory(Server.MapPath(uploadPath));
where uploadPath is the folder's name i want to create dynamiclly.
but how do I include the subfolder too in my Server.MapPath() so as to make my path as rootfolder/subfolder ?
Small example to make the question understandable.
I am a seller. I have posted 4 ads online.
Now when i am posting my 5th ad i want to include many images.
these images should be saved in the folder
Seller/5/imagename.jpg.
(where Seller is the username(main folder), 5 is the advertID in the database and the name of the subfolder)
How do i do this? Please help.
I am using asp.net c#
As far as I know, you can't do one statement to create folder and subfolders because you need the folder to be created first.
You have all of the code you need, you just need to repeat it. Check to see if the main folder (username) exists. If it doesn't create it, if it does, check to see if the subfolder exists. If it doesn't, create it.
Just work through that logic and you'll be set.
User Path.Combine to add your root and the user id:
var userPath = Path.Combine(uploadPath,userID)
This is the safest way to create what you need. The Directory.CreateDirectory method will create all the subfolders as needed:
var userPath = Path.Combine(uploadPath,userID)
if (Directory.Exists(Server.MapPath(userPath))) return;
else Directory.CreateDirectory(Server.MapPath(userPath));

Options for storing file path of the component in database

I have set of files (which are essentially ".exe" files) that I allow the users to download from my website. To have a clearer picture have a look at the this screenshot (it is just a academic project). Now I have administrator privilege in which I can upload a new software file to a folder (componentsFolder) to the root of my website and I also add the filepath to the database table at the same time.
I'm using the following code to do that:
string componentRelativeFilePath = #"/ComponentsFolder/" + ComponentName;
I'm storing the filepath in the following format in the database file:
/ComponentsFolder/FileName.exe
What is the difference between storing the files in the following formats?
/ComponentsFolder/FileName.exe
\ComponentsFolder\FileName.exe
~/ComponentsFolder/FileName.exe
~\ComponentsFolder\FileName.exe
I'm using server.mappath to retrieve the file from the root folder.
I want to know the difference (in this context) between these formats and which one is the standard/appropriate/technically correct format to store the relative paths in database table.
In terms of Asp.Net lets suppose you set your image path as "/Image/pic1.jpeg" so the image would be searched in Image folder located in website root and in that folder pic1.jpeg is searched. If your set you image source to "~/Image/pic1.jpeg" in that case as well the image file is read from the Image folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located. But '~/' this could only be used with server controls.
If path is "../Image/pic1.jpeg", in that case Image folder is searched in the current webpage's folder.
As per my opinion storing path in "~/Image/" format is a better choice in terms of Asp.Net.
Hope I answer your question.

Uploading files to site / datatable

I'm trying to make a little site for few people. Basically what i'm looking for is that users can register to this site, log on and upload files. I want the files to upload to a new folder that is named after the uID for example.
User Tommy registers and get user id 1234.
Then his upload folder will be
http://www.site.com/users/1234/upload/
He is the only one that has access to this data and can delete them.
Another way would be storing this info in the sql. I'm using MS SQL 2008. Can i save the upload attachments right in the datatable ? or should i have one account that has full rights that will make the folders for the users and save the direct link in the database ?
I'm going for a little, very so light version of dropbox.com but only in a browser form.
And if you go though folder route,
System.IO FileInfo and DirectoryInfo will give you all the info you need about the contents of a folder, and the files within it.
And dont forget Server.MapPath() :)
Take a look at FILESTREAM in SQL Server 2008, which is designed to efficiently store unstructured data.
BOL: FILESTREAM Overview

Categories

Resources