How to Set File-Location for Files Uploaded using NeatUpload - asp.net

Salvete! When we set up the asp.net file-uploading control called "NeatUpload", it saves its files to a temporary location, either "YOUR_APP_ROOT /app_data/NeatUpload_Temp/", if the directory is writable, or to the system's temp folder. However, the demo does not seem to actually upload any files, nor does it include an example for saving the files to a particular directory.
How do we save the file we have uploaded and move the uploaded file to a particular folder? My only clue from the documentation is that it has to do with UploadStorageProvider, but I need some help to implement this.

if you read the documentation 3.3 point 6 :
In your codebehind file, process the uploaded file. If you are using
the InputFile control, the uploaded file's client-specified name, MIME
type, and contents can be accessed via inputFileId.FileName,
inputFileId.ContentType, and inputFileId .FileContent, respectively.
If you want to keep the uploaded file, you must use the
inputFileId.MoveTo()method to move the uploaded file to a permanent
location. If you do not, NeatUpload will automatically remove the
uploaded file at the end of the requestto ensure that unwanted files
do not fill up the filesystem. The following code will put the
uploaded file in the application's root directory (assuming sufficient
permissions):
and so on. I hope this is what you are after.

Related

Change file permissions from code behind

I wonder if its possible to change permission on file from code behind?
PROBLEM: Unfortunately i use AjaxFileupload to upload files to webserver. So far so good. The problem arises when the uploaded files, that are saved on a mapped folder on the webserver are to be opened. The files doesnt show up in folder (on other server), lack of permissions.
Here is why: AjaxFileUpload save the file in a temp folder first, then move it to actual by me defined path. The file inherit the permission from that temp folder, not the permission i have put on my mapped folder. I need to use the mapped folder and I need the permissions on the mapped folder to be inherited to the file.
Why do i need this? I need this because there is an desktop application that need to open the files. The mapped folder have all the correct permissions for doing this. So, how to do? It would be easy if i can change permission on files from code behind, lets say just after i saved the file to folder, BUT is that even possible?
I read somewhere that it wasnt a good idea to change permission on the temp folder, any ideas why?
Any help would be appriciated!
edit:
So to clearify, i dont have any problems saving file to disk (server 3). My problem is that i cant see or access files on server 1, because the file doesn't inherit the mapped folder permissons. The mapped folder have permisson from both server 1 and server 3 but one the file get uploaded the file only have permission from server 3.
I don’t think the problem is with the permission on the source file. I believe the problem is the account used to run IIS does not have permission to access the mapped folder.
You can use Impersonation to grant access for the section of code that saves the file.
See these:
WindowsIdentity.Impersonate
This question
And this question
Solved it by myself. Basically wrote some code that gave me the name of the tempfolder on webserver where ajaxfileupload made the temp-save before moving the file to the folder i wanted it. When i had the name on that folder i basically changed permission on that folder. I only gave read and list permission on the folder because i dont want the desktop application to have any other right on the webserver. That was all i needed to get the file listed on in the mapped driver.

Bluimp Backload folder reference issue with virtual directories

I am working on a solution which has two projects in it. One is a virtual app which works in another. The first application is the panel and the second is the website. First application can be accessed with "localhost:10001/panel" and the second with "localhost:10001". You see, I created a virtual path for the first app to work under the second one in Visual Studio and they work great that way.
The problem I am having now is about the file uplaod system, "Blueimp's jQuery-File-Upload" plugin and as backend using "Backload". I must say that these work great on a standalone project. That's why I decided to continue the project using these.
But when it comes to a setup which I explained below, I cannot access the files I upload. I installed fileupload system in the panel project, which is accessed as "localhost:10001/panel" so when I leave the default web.config configuration for backload (default is "~/files"), all files are uploaded to the "localhost:10001/panel/files" path. And after the upload when I refresh the page, all uploaded file links are referencing "localhost:10001/files/" without the "panel" folder.
In BackLoad web.config notes how to change and use root upload folders are explained like that
filesRoot: // Root upload folder. If the value starts with '~/' (e.g. ~/files) the path is relative to the web root, otherwise set an absolute local path (e.g. d:/files) [Default: "~/Files"].
I understand that having "~/" at the beggining of a folder reference shows the project's root. But I can't figure out how to reference the upload folder, instead of the default "~/files", to upload and access all files from the second project's root. When I need to reference folder between these two projects I simple use "../", or "/" to access the second project's (site) root. But doing that in "filesRoot" attribute of BackLoad config settings, all file references are starting "///file....." and shows a local path in the computer.
I simply want to upload and access the files from the "localhost:10001/files" location when I upload files from the panel. Now, I cannot even use the "localhost:10001/panel/files" path because files are uploaded to "panel/files" folder, but are accessed from "files" folder with default settings.
BTW: I am using BackLoad's WebForms Example on this project, and this is a Web Forms project.
I ended up using Files folder as a temp folder. At the time of submit, I move the file which is uploaded in Files folder, to the folder of my need. And the problem is solved.
Thanks anyway...

in asp.net 4.5 with fileupload how can Check zip for file extensions

Hi i have the standard file upload control in asp.net 4.5, and i limit what users can upload by checking the file extension. All works a treat but i know need to allow them to upload a zip file.
My Problem
Now i only want to allow the zip file if the files inside are of the extenions i allow {pdf, txt, doc . etc}.
I have tried the below:
Using archive As IO.Compression.ZipArchive = ZipFile.OpenRead(File.InputStream.ToString)
End Using
The above wont work becuase ZipFile.OpenRead(Needs the path of the zip folder). So how can i acces the file without having to save it to disk. Do have I have to save it to disc in a temp folder first?
Ideally as .NET 4.5 has compression i dont want to use third party tools.
Thanks
In order to read the archive file all thats needed is as below:
Using archive As New IO.Compression.ZipArchive(HttpPostedFile.InputStream)
end using
*notice the new zipArchive here takes the HttpPostedFile.inputStream. The code snippet i was using above in my question was taken from the micorosft site http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive.aspx. Which was not working.
Thankyou #user2675751 for your comments

Creating a new file without using a ServletContext

Assume I want to write to a new file created within the space of my webapp.
One way would be use getServletContext().getRealPath("/") and use that String to create a new file on the server. However, often I come across advice like not using getServletContext().getRealPath("/").
Can someone please let me know of another way to write a new file within my webapp?
Many thanks.
Have some configuration property containing the absolute path of a directory outside of the webapp and web server path, read this path from the configuration property, and write to this directory.
To serve files from this directory, write a servlet that takes the name or ID of this file as parameter, reads the file from the directory, and sends its content to the response.
This will
work even if the app is deployed as a war file and never unzipped to the file system
allow you to redeploy the next version of the app or server without deleting all the uploaded/created files
allow you to add whatever control you want on the uploaded/created files, instead of making them available to everyone
In short, treat these files as data, stored in a database which happens to be the file system instead of a SQL database.

move dynamically uploaded files in asp

I am having a application that uploads files according to the user input..i just want to move that particular file to moved to another folder..
Now i am able to move the files to the destination folder..but it moves all the files which is already there in the folder..
i am creating a folder dynamically while uploading the files..and i need that file to be moved to that created folder...
I need to move only the uploaded file during run time...
E:\Export Documents - Copy\Uploads this path to C:\inetpub\wwwroot
this is my code
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
strDir = "c:\inetpub\wwwroot\" & fldr
oFS.CopyFile "E:\Export Documents - Copy\Uploads\*.jpg", "c:\inetpub\wwwroot\" & fldr
What you probably want to do is identify the file you have just uploaded and then move that. If you are already creating a folder to store the files in in inetpub, you might as well do the same in Uploads, and then just move that folder.
You will probably find it helpful to use fileSystemObject.MoveFolder instead of .CopyFile so that your Uploads folder does not fill up.
If you want some help with how to do that, post the code you are using to upload your file.
For working with the FileSystemObject, this is a useful reference
On another note, is it really wise to move files from Uploads into wwwroot? A malicious user could do some damage in there.

Resources