Generate id for files based on file content - c#

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?

Related

How can we prevent files that have changed the extension from being uploaded?

I have a program that allow to user upload a file.
Suppose the user is only allowed to upload the psd file (or any other file that is specified by admin user). If user changes the file extension from .exe to psd, can upload it.
How can we prevent files that have changed the extension from being uploaded?
You could check for ContentType header, but that could be tampered by someone with enough knowledge to do so.
Like MrTux pointed out, the best way would be to read the file header and check if it's complying to the file format you want to check against.
It would be easy to decide if you have information on how users are currently uploading files. If it's your own system or if users compose their own http post requests.

allowing users to download files from azure blob storage as single zip file

I have multipl files in my blob storage. Also I have a azure database table which stores url which points to actual individual files in blob storage .
On my webform user can specify search criteria.Then it will search for files that match the search condition and show a single link to download matching files all as a single zip file.
I have my search results returned as a list. for example
List searchresults
This search result will contain multiple urls
eg.,searchresults.url ="https://myblobstorage.blob.windows.net\xyz\mymusic.mp3"
if there are matching records ,it will show a single download link on the page,so that the user can click on the link and download the the matching files together as as single zip file.
I am able generate the searchresultsList with the required file urls pointing to the files in my azure blob container.
Now my Question
Is there a way I can generate a zip file by looping through the searchresultsList and grabbing files from blob and generate a single zip file for the user to download them? Give me your suggestions or some sample code to achieve this functionality.
When the user clicks on the link, it should go and fetch all the files from corresponding urls from the search results list and generate a single zip file and download to the users machine
You need to download the blobs to your server, generat a zip and push that to the client.
You can use the following lib to generate the zip file http://dotnetzip.codeplex.com/
The blobs you can download to the client via the .NET SDK provided with the Azure framework. It should be a simple solution, really.

Fetching the username who last modified or created the file

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.

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