Read CSV file selected at client side in C# through AJAX? - c#

I have a requirement in which user will select a CSV file locally, I have to read the file contents and dump them on a JQGrid. Yes, the browser is IE :)..What should I do in order to achieve this?

Actually you can do that with the all new HTML5 features, so if you are going for IE9+
http://www.html5rocks.com/en/tutorials/file/dndfiles/
Check this out.
Basically, you need the FileReader component (FileReader.readAsText(Blob|File, opt_encoding)) and then just parse everything with regexps or whatever floats your goat.
If, you definetely need to do this in client side AND in older IE, maybe ActiveX is a solution:
ActiveX' FileSystemObject

I would do it server side.
http://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx
(FileUploadControl.OpenFile)

Barring that you are not capable of using HTML 5 (lower version of ie etc.):
Javascript can't access the file system directly, so you are going to have to use the file upload tag and parse it on the server: http://webdesign.about.com/od/htmltags/p/input-file-tag.htm
You can then use AJAX to query the contents and pull it back down into the grid.

Related

InfoPath Form URL TO PDF using C#

I want to convert inforpath to pdf.
I have the url and have an access to the hosted place like :
http://hostserver/PWA/_layouts/15/FormServer.aspx?XmlLocation=/PWA/InfoPath%20Title.xml
Is there a way to read the InfoPath form as xml and converting it to pdf ?
You have to download and parse content of the URL to an object via: XElement, HtmlAgilityPack then create PDF file e.g. using TextWriter.
Depends on how and where you want to deal with it, ABCPdf,ItextSharp along with many other third party tools available let you handle the conversion on server side.
You can use jspdf or equivalent to do it on client side, analyse what you need and choose your tool.

editable word document attachment

Its a general scenario when we provide an option of attaching a file (MS .doc) to end user. This file is stored in DB as binary. When user try to access this attachment next time, we allow them to download it. Now, here I want to give a feature to user where he should be able to open this doc file on click, edit it and save it without downloading.
.doc is a binary format and not easy to work with - a library such as Aspose, as mentioned by Christian, is definitely the way to go.
However, if .DOCX is acceptable (and that's Office 2007 and higher), then you can achieve what you want in three steps:
Convert .docx to HTML
Convert Word to HTML then render HTML on webpage
Display the HTML using any rich text control of your choice
What is the best rich textarea editor for jQuery?
Finally, convert HTML back to .docx:
Convert Html to Docx in c#
You would have to "reinvent" Microsoft Office Online (look into your skydrive account). I am unsure if there are any "out of the box" libraries for that, but you could build a simple editing app by leveraging Aspose word (or some other library). But that would be far from simple.
Link to aspose: http://www.aspose.com/.net/word-component.aspx
Word will only open files that are locally stored. What you are looking for is something similar to editing items that SharePoint provides using the WebDAV interface.
You may be able to use this approach to support your requirement. You should be cautious about the security aspects of the solution unless you have fully authenticated access to the shared folder on the server.
I am not sure if a standalone MS Word Document editor exists. However, this can be done with using a combination of rich text formatting / converting tool (for example, the DevExpress ASPxHtmlEditor + Document Server):
Load binary data from a DB;
Import loaded data (MS Word content) as HTML content into the ASPxHtmlEditor;
Edit imported data via the WYSIWYG ASPxHtmlEditor;
Convert the edited HTML back to MS Word content;
Save the converted / edited MS Word content back to the DB.
I believe, it is possible to do something like this if you have such products (free or commercial analogs) in your project.

csv file upload on asp.net

User need to upload 30,000 csv values, these values may contain 16 digit numbers or zipcodes.
Now our asp.net project doesn't use AJAX tool kit controls or jquery or any other 3rd party controls or open source code. This is restriction as per companies privacy policy.
So I have to come with a best way to accommodate file upload feature. This has to be versatile in regards to re-usability some thing like a custom control
This file upload feature should not be saved on the server, instead I need to read data into stream buffer and send them to UI then once user verify these values he/she'll have to hit submit thus values will be saved to DB.
what are the best ways to implement this,
Can I make use of System.Net.Webclient? or
Is there any other alternative ways by using Async HttpHandlers?
Can I show file upload progress to UI ?
Appreciate if you could help me with proper guidence on this.
Thanks in advance
krish
Well 30,000 values of zipcode or any other 16 digit code should be uploadable normally using file control(i mean via postback).
if you have to read and show 30,000 on the UI, i presume you are at risk of freezing your UI.
Moreover if you are not on HTML5, there is no way that you can read the content on the client side, except if you fiddle around with flash.
HTML 5 file api reference
http://www.html5rocks.com/en/tutorials/file/filesystem/
How to read and write files with Flash(Action script)
http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/

How to save textbox data to file using javascript

I have a web page containing a textbox. This textbox shows result of processing. There is a button "Save Result" to save contents of textbox to file. I know it can be easily done with FileStream. But I want the same functionality to save file using Javascript so that there is no need for server postback.
Do anybody have solution to this?
Thanks for sharing your time.
As Darin said JavaScript works on the client's side.
As far as I know you won't be able to create files on the user computer using javascript.
A little google-ing mentioned it being posible with JScript/ActiveX/IE (Never tried it).But I would suggest a different approach. Good luck!
You can save it to the client's file system using html5's local storage, however it will only be available to that website.

Save a binary file in SQL Server as BLOB and text (or get the text from Full-Text index)

Currently we are saving files (PDF, DOC) into the database as BLOB fields. I would like to be able to retrieve the raw text of the file to be able to manipulate it for hit-highlighting and other functions.
Does anyone know of a simple way to either parse out the files and save the raw text on save, either via SQL or .net code. I have found that Adobe has a filtdump utility that will convert the PDF to text. Filtdump seems to be a command line tool, and i don't see a way to use a file stream. And what would the extractor be for Office documents and other file types?
-or-
Is there a way to pull out the raw text from the SQL Full text index, without using 3rd party filters?
Note i am trying to build a .net & MSSql solution without having to use a third party tool such as Lucene
If it isn't absolutely necessary to stream directly from SQL Server into your app, the hard part is parsing the PDF or DOC file formats.
The iTextSharp library will give you access to the innards of a PDF file:
http://itextsharp.sourceforge.net/
Here's a commercial product that claims to parse Word docs:
Aspose.Words
Edited to add:
I think you're also asking if there are ways to make SQL Server Full-text Indexing do the work for you by adding IFilters. This sounds like a good idea. I haven't done this myself, but MS has apparently supported a Word filter for a long time, and now Adobe has released a (free) PDF filter. There's a lot of information here:
Filter Central
10 Ways to Optimize SQL Server Full-text Indexing
SQL Server Full Text Search: Language Features - a little out of date but easy to understand.
SQL Server Full-Text Search feature uses IFilters for extracting plain text from PDF or Office file formats. You can install IFilters on your server or if your code is running on the same machine as SQL Server you're already have it.
Here is an article which shows how to use IFilters from .NET: http://www.codeproject.com/KB/cs/IFilter.aspx
You could from your C# application open the .doc file and save it as text and put both the text and .doc document into the database.
If you are using SQL 2008, then you could consider using the new FILESTREAM feature.
Your data is stored in a varbinary(max) column, but you can also access the raw data via a regular Win32 handle.
Here's some sample code showing how to get the handle.
I had this same issue... I solved it by adding the following to my application:
EPocalipse.IFilter.dll (for everything -but- Office 2007
documents, due to 64x Windows issues)
OpenXML SDK 2.0 (for Office 2007 Documents)
I use these to grab the plain text and then store it in the database alongside the binary data. Keep in mind that I am certainly not an expert, so there may be a better way to do this, but this works for everything but "Quick Save" pre-2007 Word Documents, which apparently aren't read by iFilters. I just have my users resave the document if that error occurs, and everything works fine.
Let me know if you'd like some sample code... I would post it right now, but it's a bit long.

Categories