I have to read the first couple of lines of a csv file client side to present the user with a preview before uploading a large file.
I'm using c# with ASP.Net (VS2010)
Does anyone know how this can be done? Also that it works in all browsers!?!
(It's not possible to use activeX or so, we do not want our clients to install something!)
A sample code would be great!
Thanks in advance!
Firefox 3.6+ and Chrome (at least version 6, possibly older versions) support the File API which lets you read local files from a file input.
Here's a quick sample:
function handleFile(file) {
var reader = new FileReader();
reader.onload = function(e) {
// Here's where you would parse the first few lines of the CSV file
console.log(e.target.result);
};
reader.readAsText(file);
}
in your html, you would have something like this:
<input type="file" onchange="handleFile(this.files[0])" />
Of course, in real life you should make it degrade gracefully.
The file object has name and type properties that you could use to verify that it's a CSV file if you wanted to be more strict.
There is a W3C proposal for a File API in HTML5. I ran a few browsers against this test, and found that Firefox 3.6, and Chrome 6 support File Reader API and Local Storage. Safari 5 (on Windows) supported Local Storage but not File Reader API. Sorry I couldn't test IE9 as corporate policy has IE6 (?!) nailed in place.
You can't read a local file with vanilla JavaScript.
You could use activeX as a progressive enhancement to those using IE (even though offering an enhanced experience to IE users goes against everything I stand for!).
If you can use Flash, look at Read local file in Flash.
Related
I'm trying to download JDK15 but i downloading 5307 bytes but this are not the JDK15
using (WebClient wc = new WebClient())
{
wc.DownloadFileAsync(new System.Uri(
"https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe"),
Path.Combine(directoryPackagesPath, "jdk.exe")
);
}
You downloaded a web page instructing you how to access the download:
You cannot directly download that file. If you open it in another browser, or a incognito/private window, you will see this message:
Sorry!
In order to download products from Oracle Technology Network you must
agree to the OTN license terms.
If you open the downloaded file, most likely it's an HTML with this message.
It is illegal, but if you want learn how to do it for some CTF etc.:
Get query what is send after accepting licence by dev tools in your browser.
Send the exact same query by HttpClient and get cookies from response.
Use this cookies to get the file.
If you want this particular version, you can attach it (if licence allows you to do that) to your program by using installer, by resources or even as normal file in output directory.
I have a SharePoint server and I want to open files directly from the Server with SharePoint CSOM.
User clicks button --> the file (Excel, Word, ...) opens at the client machine with the standard software.
Directly means, that if I change something to the file and click save, that the file is directly saved on the SharePoint server (or if I click e.g. 'Save as' in Excel the suggested path is 'https://sharpoint.url.com/folder').
Actually I have:
using Microsoft.SharePoint.Client;
var clientContext = new ClientContext("https://sharpoint.url.com");
string relativePath = "/folder/file.xls";
clientContext.Credentials = CredentialCache.DefaultCredentials;
var file = clientContext.Web.GetFileByServerRelativeUrl(relativePath);
clientContext.Load(file);
clientContext.ExecuteQuery();
What do I have to do now, if I want to open the file directly (no download)?
I assume you ask how to access the file's stream instead of downloading it to a local folder.
You can use the File.OpenBinaryDirect method to get access to its ETag and stream, eg :
using(var fileInfo=File.OpenBinaryDirect(clientContext,"/folder/file.xls"))
using(var reader=new StreamReader(fileInfo.Stream))
{
//Do whatever you want with the data
}
BTW you shouldn't use the old xls files. The format is deprecated for over 10 years. The current Excel format, xlsx, is a zipped package of XML files that's better supported by SharePoint itself, doesn't require Excel to generate or read.
For example, if you wanted to read cell values from an xlsx file, you could use the popular EPPlus library to read directly from the stream:
using(var fileInfo=File.OpenBinaryDirect(clientContext,"/folder/file.xlsx"))
using(var package=new ExcelPackage(fileInfo.Stream))
{
var sheet=package.Workbook.Worksheets[0];
var value=ws.Cells["A1"].Value;
//...
}
UPDATE
It seems the question isn't related to programming after all. All that's needed to save or open a SharePoint document is clicking on the document's link. What happens then depends on the Open Documents in Client Applications setting at the site and document library level.
This affects the headers the server sends to the browser when the user clicks on a document link. The browser may still refuse to open the registered application and display the Save dialog.
If that doesn't work, you should check why instead of writing code. It's probably a configuration error or a browser setting. Solving it is easier than creating workarounds, pushing them to all client machines. And then keeping track of all the patches, where they are deployed and deploying new ones.
Apart from that, the Office applications know about SharePoint and document libraries since 2003. They can browse them, display SharePoint properties for the document, show collaborators etc.
As I mentioned in the question comments, a lot of what people think as "SharePoint Developoment" is nothing more that configuration, administration and end user features.
MSDN docs don't help either - they actually cause harm by not covering SP administration or explaining the features and how they are used. You'll find that in Technet. For years, people created webparts in code to change how grids looked because MSDN didn't explain how eg the DataViewWebPart worked or how you could style a grid from the UI.
In general, the best place for such questions is http://sharepoint.stackexchange.com. For example, check “Open in the client application” Vs “Use the server default (Open in the client application)” inside the document library advance settings
We can create Map Network Drive for SharePoint library, and open the file from the network location. Check article below:
http://support.sherweb.com/Faqs/Show/how-to-connect-to-a-sharepoint-site-using-webdav-sharepoint-2013
Or we can download the file from SharePoint and open it using the code below:
Application.Workbooks.Open(#"C:\Test\YourWorkbook.xlsx");
Reference: https://msdn.microsoft.com/en-us/library/b3k79a5x.aspx
i created a application with function export report as pdf file, the application can download the report in web format.
i run the application in my pc, it is work, but i try run at user pc, but fail when exporting
Using _report
_report.Load(HttpContext.Current.Server.MapPath("Report/" & "report.rpt"))
_reportname = name & date.now
_report.ParameterFields("name").CurrentValues.Clear()
_report.ParameterFields("name").CurrentValues.AddValue(_name)
_report.SetDatabaseLogon(_gstrID, _gstrPassword, _gstrDataSource, _gstrCatalog)
_report.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, context.Response, True, _reportname)
_report.Export()
_report.Database.Dispose()
_report.Dispose()
any miss take in my code???
There are many things that could be happening here.
First, test it from a completely different computer that the two you have. Test it on the same computer with the problem using a different browser. Optionally, update your version of Adobe Reader on the misbehaving machine and try again.
Next, if you are using IIS 7.5 there is a hotfix concerning downloading PDF files ( http://support.microsoft.com/kb/979543 ) that impacts particular versions of the Adobe PDF Reader plug-in.
I seek some insight in creating an application that converts text to speech in ASP.NET. From my initial research, it appears that:
MS SAPI requires the client to download an ActiveX component and can support large amounts of text to be converted. Our clients are not willing to install any components on their systems, so this approach may or may not fly.
I do understand with .NET 3.0, we have the System.Speech.Synthesis namespace. Does the conversion take place on the server? If so, how would I serve it to the client?
Our requirements are ability to convert large amount of text, should be scalable and reliable. Which technology is "production ready" capable of serving a large number of requests in a short time interval.
Any thoughts are appreciated.
By default, ASP.Net applications don't run with sufficient permissions to access Speech Synthesis, and attempting to run Larsenal's code will fail with a security error.
I was able to get around this in an app by having a separate WCF service running on the server, as a regular Windows Service. The ASP.Net application then communicated with that service. That service just wrapped Larsenal's code, returning an array of bytes, given a string of text.
Also, one megabyte of text? That's a good-sized novel.
Edit, 11-12-09, answering some comments:
System.Speech can either return an array of bytes, or save to a wav file, which you can then feed to a media player embedded on the user's page. When I built my talking web page, it worked like this:
1) Page.aspx includes an 'embed' tag that puts a Windows Media Player on the page. The source is "PlayText.aspx?Textid=whatever".
2) PlayText.aspx loads the appropriate text, and communicates (via WCF) to the speechreader service, handing it the text to read.
3) The Speechreader service creates a MemoryStream and calls SpeechSynthesiser.SetOutputToWaveStream, and then returns the stream as a single array of bytes. This array is Response.Write()-ed to the client.
Here's the meat of the SpeechReader service:
byte[] ITextReader.SpeakText(string text)
{
using (SpeechSynthesizer s = new SpeechSynthesizer())
{
using (MemoryStream ms = new MemoryStream())
{
s.SetOutputToWaveStream(ms);
s.Speak(text);
return ms.GetBuffer();
}
}
}
I'm pretty sure that on the back end, this returns an enormous XML array-of-bytes, and is horribly inefficient. I just did it as a proof of concept, and so didn't research that. If you intend to use this in production, make sure that it's not internally returning something like this:
<byte>23</byte>
<byte>42</byte>
<byte>117</byte>
...
With the SpeechSynthesizer, you can output to a WAV file. You could then have a secondary process compress or convert to another format if needed. All this could be done on the server and then sent up through the browser.
This CodeProject article is a good introduction to .NET Speech Synthesis.
If you want to see how it performs with a LOT of text.... Add a reference to System.Speech and then use the following as a starting point:
using System;
using System.Speech.Synthesis;
namespace SpeakToMe
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer synth = new SpeechSynthesizer();
synth.SetOutputToWaveFile("c:\\test.wav");
synth.Speak("Hello, world.");
synth.SetOutputToDefaultAudioDevice();
Console.ReadLine();
}
}
}
A quick test on a file of 44,700 words (238KB) on my relatively fast machine...
Completed in 55 seconds
Generated a 626 MB WAV file
I searched for "Convert Text Into Speech In Asp.Net" in Google and found a very nice and usefull link:
http://codeprojectdownload.com/asp-net-2/convert-text-into-speech-in-asp-net/#.T0ScXIfXDZE
It may also be useful to you.
I achieved this by using codeBehind to run a javascript function that runs the text-to-speech command:
codeBehind:
Page.ClientScript.RegisterStartupScript(
GetType(),
"anythingHere",
"nameOfFunction();",
true);
javascript:
<script>
function nameOfFunction()
{//start
var msg = new SpeechSynthesisUtterance('READ ME!');
window.speechSynthesis.speak(msg);
}//end
</script>
I wrote an article on this on my blog: http://weblogs.asp.net/ricardoperes/archive/2014/04/08/speech-synthesis-with-asp-net-and-html5.aspx. I used AJAX and Data URIs to send voice data back and forth between the client and the server.
Our ASP.NET/C# lets users edit and manage Word (OpenXML) documents that are hosted on a server. I am using client-side VBScript functions to handle some of the editing functions including saving the document to a folder on the server. For the save functionality, I am using the following function call :
Document.SaveAs "http://server/savefolder/savefile.docx"
I have given "Full Control" permissions on savefolder to both the NETWORK SERVICE and the IUSR_MACHINE users. Yet the above call fails. The error number returned is 5096. The error message is some gibberish that doesn't make any sense.
The server is Windows 2003 and the IIS version is 6.0. I have installed the OpenXML SDK 2.0 CTP on the server.
I can successfully read and print documents.
Does anyone tell me what I am doing wrong? or what additional settings need to be in place?
BTW, the error message ("gibberish" from my post) is:
"EOALPHABETICARABICARABICABJADARABICALPHABAHTTEXTCAPSCARDTEXTCHARFORMATCHI"
No, I am not making this up!
In my case, that error 5096 with description "EOALPHABETICARABICARABICABJADARABICALPHABAHTTEXTCAPSCARDTEXTCHARFORMATCHI"
occurred when using VBA code in Access to drive a Word mail-merge. The cause was trying to save a document with the same name (including path) as an open document.
Error line:
objApp.ActiveDocument.SaveAs saveAsName
where objApp is the object variable representing the Word application and saveAsName is the string variable storing the name I am trying to save the file as e.g. "C:\temp\testdoc.docx".
IF a file with the same name exists but is not open, the above code overwrites it silently.
Turns out WebDAV is not turned on by default in IIS 6.0. Once I turned it on, I was able to save the documents just fine.
Thanks for all your answers!
Just a guess... if the vbscript is running on the client, the code is probably running under the user's account, not under the server's IIS account. So unless you give write access to that user, vbscript probably won't work for this.
Since you're using ASP.NET, you could try writing a web service that takes in Word document data and saves it to the server for you.
I'd try running Fiddler on the client while trying to save the document to get a sense of what's really going on. I wonder if maybe it's trying to do an HTTP PUT (as opposed to a POST).
Have you given write access to the folder in IIS manager?
Is the save folder you're using outside of the websites root directory, i.e. 'hidden' from the internet?
Just to add to SI's information...
I also get this I get the 5096 - EOALPHABETICARABICARABICABJADARABICALPHABAHTTEXTCAPSCARDTEXTCHARFORMATCHI error when my code tries to save a MS Word document with the same name and to the same location as a Word document that is already open in another instance of Word.
Although not entirely relevant to this thread, I hope it may help someone else who stumbles upon this thread!
Regards,
Duane,
this question is old but still active ?
You save the file with a http://... url, i think you should save it with a file URL as
Document.SaveAs "\\server\savefolder\savefile.docx"
Grtz