How to validate data inside a csv or excel file? - asp.net-mvc

I currently have a mvc task to validate the data inside the csv or excel file before it uploads to sharepoint.
I need to validate the data such as phone number format and other types of data inside the uploaded csv or excel file.if the phone number format inside the file is not correct(ex: (985)-265-abcd) the file should not validate/upload and it has thorw validation error.
Is there any way to achieve that kind of functionality

You need to create an event receiver that fires when the item is being added to the library. At that point, you need to get your file, run the validation logic, and if validation fails, cancel the event to prevent the file from uploading.

Related

Rails upload excel file, validate and save

I am working on a rails engine that uploads a excel file, validates it and if there is no error than it will save it to database.
Now when ever a user mounts the engine and than go to the route provided by engine. He will have a form to upload the excel file. There are two buttons on page, i.e, upload and validate.
Once a user choose the file and when he click on upload i want that file only gets uploaded and don't get saved in db. Once i get the message the file is uploaded successfully, than i will validate the file. If it is a valid excel file with valid data than it will be saved into db. Now i am not getting how to go about it. I have seen this Railscasts video on uploading csv and excel file but here he is performing validation and save operation with import action but i want validation and save operation when user clicks on validate action. This Questions seems similar to my problem but i am not getting how do i access that uploaded file. I don't want that file to be saved in database. I mean when a user click on upload button that file gets only uploaded not saved. Than i will validate that file and save it's content to db.
This may seem very easy and simple questions for some experts but i am very new to rails and i am not sure how to go about it.
Someone please help me with a sample code, so that i can understand the workflow. Also note that both upload and validate actions are on same page. So when a file gets uploaded it needs to be stored somewhere temporarily, this is the first problem i am facing. I can do all the task if someone can tell me workflow with a sample code about uploading excel file. I am only having problem here that as both upload and validate action are on same page, so after upload request it needs to be on that page so that i can validate that file.
Any help would be appreciated, I am very beginner at rails and really confused here.
Two options:
Write code to upload the file and save to DB with a validated column set to false. Then the 'validate' button will locate the unvalidated file, validate it and set validated to true. You could have a periodic job deleting unvalidated files of a certain age. If you do this, use a helper gem like Paperclip.
Forego file upload frameworks and just manually save uploaded files to Tempfile.new 'spreadsheet'. This guide takes you through how to do that. Save that filename to session and use it to validate at a later point. When you're finally ready to persist to DB, again, consider using a helper gem.

Rails, Audit Log in View

I have a Model called file.rb that handles a files data table. This was done so that I can upload excel files from a file index.html.erb, and have the file name stored, see who uploaded the file, when it was created, etc(just tracking the files). These Excel files have many rows and each row have a bottle object with many attributes. During the create method, after save, I send the uploaded file to another model `bottle.rb'.
The bottle.rb model handles opening the Excel file and importing the information from the Excel file into the bottles data table.
I would like to be able to create an audit log with a message telling me success or failure of an uploaded excel file. Once the file passes the validations, I would like to see how many updates and new inserts to the bottles table. And be able to see this in the view where I upload the Excel file. I appreciate any helpful tips! I made an activity feed but for the entire application, but I am unsure how to go about to do this task.

Importing csv/xls format files with smartGWT

I am using smartgwt free version (not EE). Is there a built in widget to handle importing .csv or excel format files?
I can currently export records from a listGrid to csv. I want to be able to open up another browser, and import the csv file, and based on the configuration that I have exported onto the csv file, re-create the records that I have exported.
I've done the same thing, to achieve that I would suggest a custom datasource using gwt-rpc. You can get the code here.
https://code.google.com/p/smartgwt-extensions/
The thing is I've used gwtupload to send the excel file to the server. Once that is done call fetch to your custom datasource with the file path that was uploaded to the server. Using Apache POI on the server side to parse the data and return that as a result to your datasource fetch call. Within the execute fetch create Record objects and add them to your grid.
you can get the gwtupload from here,
https://code.google.com/p/gwtupload/wiki/GwtUpload_GettingStarted

Rails, Upload and Parse Text File to Database

I have an advertising site running where users can post "headlines" and "sublines" in a form. I want to take this thing further.
Users should upload their .txt or .rtf file, comma seperated, so that it's created in my database.
Let's say this is the users rtf or whatever:
This is my headline; This is my subline;
This is my second headline; This is my second subline;
How can I achieve that this is parsed and written to my database? No csv or whatever. Just a simple text file.
Where should I put this form?
How can I parse it?
You might want to look at using Paperclip to upload the file & then you'll be able to access its data using this answer: How do you access the raw content of a file uploaded with Paperclip / Ruby on Rails?

Kendo UI upload control remove firing after save when multiple set to false

I am using the Kendo Upload control and need to allow the user to only upload one file at a time. I set the multiple option to false on the client side and this works. However, if a user uploads a file and then immediately tried to upload a second file, the removeUrl is called first which gets passed a string array of file names. Here is the problem, when I save a file I am renaming the file to a name using guid values and creating a database table entry to associate the file with the user. I need a way to reset the filename to the guid after the file is uploaded and its name is displayed? Is there a way to do this?
Try utilizing the Files configuration option. With that, you should be able to reset the displayed file names to any name you choose.

Resources