Uploading files using AJAX and JQuery in an ASP.NET application - c#

I have several input type files in my asp.net Web Form.
How can I upload files to Server using Jquery, AJAX and C#?
The uploaders are generated programmatically so I cannot upload the files using code behind.
Also, many files must be uploaded at once.
Is there anyway I read the file via Jquery, send it via AJAX to server and upload it there?
THanks

Have a look at Fine Uploader. It does not use flash or java. In fact, it does not have any required dependencies. An optional jQuery plug-in is provided, if you use jQuery though.
Support: IE10-7, Chrome, Firefox, Safari (OS X), as well as Android tablets and phones, along with IOS6 tablets and phones (iPhone & iPad). The Microsoft Surface tablet has also been tested.
There are many features to choose from. Have a look at the demos and, more importantly, the docs and associated blog posts for more details.
Furthermore, there are many server-side examples that may be helpful during integration of this library into your app. See the server directory in the Github project. ASP.NET is one of the many examples.

Related

Scrape a javascript-generated website in C# without installing a browser

I am developing a website crawler API to scrape a javascript-generated website. The website that we are crawling requires the Javascript to be enabled to fully-render the HTML. I have tried many solutions such as HtmlAgilityPack and AngleSharp, but they are just HTML parsers and they cannot render the page due to missing Javascript capability.
I tried implementing headless browser using Selenium.WebDriver.ChromeDriver, it worked very well in my local machine. However, our production environment is very limited such that only Internet Explorer browser is available and we are not allowed to install any more browser. So this chromedriver did not work, too. Internet Explorer cannot even fully render the website from the browser itself. So IE is definitely out.
Is there a way to scrape a javascript-generated website without having to install a browser? Like implementing a headless browser on a server without that browser installed?
Or is it a dead-end situation. Thanks!
You can try using a solution that uses a fully-functional built-in Chromium and doesn't require installing Google Chrome in the target environment. All the required Chromium binaries will be shipped with the solution.
There are many such solutions for .NET and C#:
CefSharp
An open source .NET wrapper around the Chromium Embedded Framework (CEF). It allows you to embed Chromium in .NET apps.
Supported by community. If you need help with the library use, read docs or ask community. If you need a feature or a bug fix, you would probably need to do it by yourself.
DotNetBrowser
A commercial library that allows integrating a Chromium-based browser with your .NET app to display and process HTML5, CSS3, JavaScript, etc.
It's a proprietary solution supported by a commercial company. If you need help with the library use, read docs or get help from the engineers of this product. If you need a feature or a bug fix, it will be done by the product team as soon as possible. I know that, because I know the engineers from DotNetBrowser team.
WebView2
This control allows you to embed web technologies (HTML, CSS, and JavaScript) in your native apps. The WebView2 control uses Microsoft Edge (Chromium) as the rendering engine to display the web content in native apps. With WebView2, you can embed web code in different parts of your native app, or build all of the native app within a single WebView instance. Supported by Microsoft.
If you need some help, you should contact WebView2 team.

C# WPF, and data exchange with the browser

I've a C# WPF application developed in VS 2015, and I want the browser to read some data from it. Just a short string. I can save it in a text file, or in a variable but it should be visible to the browser (using JS I suppose). For instance using file:/// doesn't work if the original page is hosted online - as in my case (different source conflict). This should work in Opera and FFox, but looking at their extensions, it seems you can only develop with front-end technologies, which are not enough in my case since I use WPF to look into Win OS, and then I need to share the result with the browser.
I suspect it's possible, and no , it's not to write a malicious piece of code. For instance I can read the details of the graphic card for diagnostic purposes.
Please help, many thanks.
Browsers run in a security sandbox which is intended to stop them reading or writing files to the file system.
You could write to the user's appdata. There are various javascript frameworks which persist data to there so they can provide offline or static data.
I don't think that is a good plan though.
I suggest your first candidate would be a cookie.
Quick google on how to do that, I find:
How to create cookie in c#.net windows application?
From a web page you can use the content of a cookie dynamically. So you could change what you see in the web page after it's up and running from some process in your wpf app and do a counter or whatever.
I've not used this with windows apps and a browser but I have with a web app and Silverlight. I'm afraid I don't have that code to hand though.

How to communicate with Google Chrome using C# or Python

I'm developing a software on C# which has to get info from a website which the user opens in chrome, the user has to input some data and then the website returns a list of different items.
What I want is a way to be able to access to the source code of the page in order to get the info, I cant open the web myself as it doesnt show anything because I didnt input any data, so I need to get it directly from chrome.
How can I achieve this ? A chrome extension ? Or can I access to chrome directly from my software ?
Off the top of my head, I don't know any application that gets data directly from an open instance of Chrome. You'd have to write your own Chrome extension.
Alternatively, you can open the web browser from your application initially.
You can look into these libraries for doing so:
Watin (My personal favourite)
Selenium
Awesomium (You'd have to roll out your own UI, it's invisible)
Cef
Essential Objects Web Browser
EDIT: I didn't think about using QA tools as the actual browser hook as #TheAnathema mentions. That would probably work for your needs.
You're going to need to create it as Chrome extension if you must be dependent on the user actually going to a specific web site (i.e. not being able to do the requests yourself with either Selenium or standard web requests in Python).
The reason why a Chrome extension would be required is because think of how bad it could be for any software to easily read the pages you browse. Banking, medical, email, etc. could all be accessed anonymously from any process if Google allowed any outside process to tap into the web page.
Even Chrome extensions have to ask for permission to be able to do what they want, but at least it is software the user knowingly installed and agreed to the permissions.
A quick search yielded this example of modifying a page's HTML with a Chrome extension: https://blog.lateral.io/2016/04/create-chrome-extension-modify-websites-html-css/
It sounds like you want to do web scraping. Here's a good tutorial to get you started: HTML Scraping.
And this answer has a good example of how to scrape data from a website where you need to submit a form to get access to the data.

C# .net Offline page?

So I have here a .NET C# web app that needs one page able to be viewed offline as a user could be off in the middle of 'whoop whoop' with no internet.
The order of events are:
User visits a form online
Store the webpage using HTML5 so they can visit it later offline
When online - the user then can submit the form to the database
I've been looking over HTML5 appcache however it seems to only reference physical .html or .php pages rather than storing pages which have been generated by 'Razor' .cshtml Views.
e.g. domain.com/path/view.
I haven't been able to find any relevant documentation for my problem either.
So is it possible to cache a .NET webapp ofline?
Although I have not tried it, and assuming your app uses ASP.NET MVC, this might help you:
Build an HTML5 Offline Application with Application Cache, Web Storage and ASP.NET MVC
It uses HTML5 Offline Web Application API (or HTML Application Cache). Note the comment on browser support.
The linked article shows a sample application, but I could not see a link to a downloadable source code. But one commenter appears to have recreated the project.
The appcache is what you need. Note that you specify the pages to be cached, but the browser never sees if the page is a static .html or generated via Razor. As long as the path you specify opens the right page, it will be cached.

How to preview a image before uploading it to the server?

I have a form that will adding the product to the online store, and contains this many fields
1) Product Name
2) Product Code
3) Product Description
4) Product Price
5) Product Image
now i wanted that while user/admin select a image using file upload control of asp.net, after selecting product image that will be displayed in image control before the user will upload that to the server.
all i need is to preview that image before it will uploaded to the server, it will be by using any of these javascript, jquery, Ajax or c#
please help me...
Thank in Advance.
Tejas Vaishnav
C# executes on the server so the image has to be already there.
Javascript and jQuery run client-side so you could have more luck with these two ( in fact JQuery is just a JS library on top of the JS engine in the browser ).
Why don't you use the preview feature of the browser's open/select file dialog anyway?
You need a script that uses a dataURI for Gecko...
This may not work with default security from a web server but does work if you load the page from your harddisk
http://javascript.internet.com/forms/image-upload-preview.html
You cannot quiet possibly do it just using JavaScript unless you use Flash or some other ActiveX plugins. It is because you cannot access the client machines resources without permission due to security reasons. You can only upload on the server and preview it. Hope this makes sense to you.
Quick googling didn't show any promissing results (at least one working in cross-browser manner). Your best shot is using Flash (version > 10, since it was the first version that enables you to access local files picked by user). It can be simple Flash (or Flex) application, you can find many examples of manipulating/showing user selected files before sending them to the server. Here you can find example of such application (made by me). You can pick image from your local disk and it is displayed / can be manipulated all before uploading it to the server.
Check the simple example of previewing an image before uploading it (Flex)

Categories

Resources