I have a form that requires a file to be uploaded as well as additional data (name, etc...) with validation on these fields. When an error occurs, the file has to be re-uploaded. Is there a way to keep the file after a validation error occurs? This is built in C# .NET.
Tried to google this but nothing helpful came up.
Thanks in advance!
You can't genually persist the file because of Security Purpose..
If page is posted and validation error occured, check for a file using the .PostedFile property, and if one exists, save it to a temp file. In Session, store a reference to the temporary file. (use javascript)
.PostedFile is a property of the FileUpload control.
Also, during my google research, I found AJAX RadControl related to your question..
http://www.telerik.com/help/aspnet-ajax/asyncupload-persist-uploaded-files.html
I'm taking a bit of a guess at what you're doing since you really can't persist a file... are you simply using a fileupload dialog box and taking it from there? If so, it's typical to put the file/path obtained from the dialog in a txt field, then do your post (upload) with a separate button.
This scenario assumes you want to persist the path/file name, but not the actual file.
Related
I need to save locally (on a file) a StackLayout object, because I need to save the current state of a page, so I was just wondering if could be possible.
EDIT: Solution
As I have seen, there is no solution!
This is because Views are not serializable, so it's neither possible to serialize the Views as a string (trust me, I have tried them all), the only way is to re-generate your page by saving and loading data of simple types such as int or string (because only simple data can be serialized).
According to your needs, I think you only need to save the user's data and restore it at startup.
You can use File Handling in Xamarin.Forms to save the user's data, and then rewrite the OnAppearing method every time it starts, and restore the data inside the method.
For more information about File Handling, please refer to:https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/files?tabs=macos#saving-and-loading-files
I am using Telerik RichTextBox Editor(the one like MS Office) in my WPF project. When I save a file, and attempt to save it again later after making changes it opens up the SaveFileDialog and asks for the file name even though I've already defined it and saved it (like it thinks I'm using Save As, rather than Save). How can I solve this issue??
I am using
<telerik:RadRibbonButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=SaveCommand}" Size="Small"
SmallImage="pack://application:,,,/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/save.png" Text="Save" />
Didn't got a solution yet from anyone. Working on it, have some progress using CustomSaveCommand. Will post a complete solution when I get one.
If anyone gets one before I do, I'll accept it. Thanks all.
Solution:
Got a solution. Created a custom OpenCommand using the CustomSaveCommand and radrichtextbox-Import/Export. Hold in a string variable, the full path of the file on open/save a document, and overwrite the file on next save without the filedialog. Also reset the variable on new file open. Hope it helps anyone who is searching for a solution. Cheers :)
You could possibly setup a custom filebrowser provider and do what you want in there, i.e. see custom filebrowsercontentprovider. Besides a few other bits and bobs just inherit from Telerik.Web.UI.Widgets.FileBrowserContentProvider class.
Here is a nice example of using a sql database for the files: sql database
I have 3 FileUpload controls. They lose their content when the page PostBack. The page is post back when I click on a button to show some hidden controls.
what can I do to keep their contents without using session ?
This is actually security related. Imagine visiting a site with a file upload and the path pre-filled with something like "c:\Users\Meensat\passwords.docx". You hit submit, and they have your passwords.
What you can do on postback is check for a file using the .PostedFile property, and if one exists, save it to a temp file. In Session, store a reference to the temp file, the file name, etc.
EDIT
.PostedFile is actually a property of the FileUpload control.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.postedfile.aspx
That link has sample code showing how to save the file to disk.
There really isn't a way around this due to the way HTTP/Forms work. The file will get submitted on the first post to the server. You could also store the file bytes in ViewState but postbacks will be slow. Your options are to not perform a postback and use javascript or other alternatives to get the same functionality or store the file somewhere on the server (ex: session, temp folder, database).
Save the content of FileUpload control in serverside. or u can render it in the html page and keep it hidden using CSS
I am having the following issue, when a user fills in a form, I make an xml file based on that information and copy a file from one folder to another. (The filename is input by the user).
If the file already exists however, there will have to be a user input on whether to overwrite this file or not. I know I can't use a messagebox and if I do whether to use javascript or jQuery, I'd be adding a page as well. Preferably, I'd like to stay in C# but thats not possible without the messageboxes.
I have looked around google and stackoverflow, and the best I can think off is creating an extra page for this, where if the file exists, the user has to pick one of two options and then go back to moving the file (or not).
I am new to ASP MVC and I was wondering if this was the best way to go about it and what the best way to go is if it isn't.
Using JQuery you could make an ajax call to a controller to see if the file exists and show the user a dialog asking if they would like to overwrite the file if it exists. I can't see that you'd need a view for this at all.
Without using a third-party control, is it possible to automatically begin uploading a file as soon as the user selects a file and the file browser window closes? I have the data struture in place as well as all the information needed to capture the data, but I need a way of knowing if the file upload has changed? Is there an event that fires, or something I can capture to achieve this?
Thanks,
George
No. Not without using a third-party control.
It looks like it is possible using a hidden <IFRAME>. Check out the AJAX File Uploader.
There are simple Silverlight and Flash solutions available as well, however.