Hi,
I want to know, is it possible to print/Load a document at/from a specified locatio/path/URL.
I mean the method to print will accept file path/URL and find the file there in the path and print/load that.
Can we use someother code otherthan the one given below to load
private static RadDocument LoadDocument()
{
RadDocument doc;
using (Stream stream = Application.GetResourceStream(GetResourceUri("demo.docx")).Stream)
{
IDocumentFormatProvider formatProvider = DocumentFormatProvidersManager.GetProviderByExtension(".docx");
doc = formatProvider.Import(stream);
}
return doc;
}
private static Uri GetResourceUri(string resource)
{
AssemblyName assemblyName = new AssemblyName(typeof(MainPage).Assembly.FullName);
string resourcePath = "/" + assemblyName.Name + ";component/" + resource;
Uri resourceUri = new Uri(resourcePath, UriKind.Relative);
return resourceUri;
}
5 Answers, 1 is accepted
The approach described below seems to be the right one. We do not have an API that shortens the path of achieving such task.
If you have any specific problem with that approach please do not hesitate to get back to us again.
Greetings,
Vesko
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
The current approach is that the Resource/Document should be included in the Silverlight project and it should be packed into XAP file along with other Dlls/Files as part of Build. then only it will be identified with the below code.
AssemblyName
assemblyName = new AssemblyName(typeof(MainPage).Assembly.FullName);
string resourcePath = "/" + assemblyName.Name + ";component/" + resource;
Uri resourceUri = new Uri(resourcePath, UriKind.Relative);
But I want this to be done in another way, I dont want to include the document in the project, the document is available in a different folder in the user machine or a server or in a network folder. What I know is the path of the document and with that path as argument I want to print that document in runtime.
Is this possible? If so can u give me a sample which does this.
Thanks,
Uday
To have your task solved you should provide an opened Stream to the document which is placed on your server. This could be done by using WebClient class. You can try the following:
private void btnImport_Click(object sender, RoutedEventArgs e){ Uri url = new Uri("/test.docx", UriKind.RelativeOrAbsolute); WebClient wc = new WebClient(); wc.OpenReadAsync(url); wc.OpenReadCompleted += (s, args) => { if (args.Error == null) { IDocumentFormatProvider formatProvider = DocumentFormatProvidersManager.GetProviderByExtension(".docx"); this.radRichTextBox.Document = formatProvider.Import(args.Result); } };}If you have any further questions, please do not hesitate to contact us again.
Best wishes,
Vesko
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
Hi Vesko,
Thanks for the explination and the sample code. It works fine, but my job is only half done.
Now, I am able to load a document which is available in the root folder of my web project.
But for suppose, my document is not in the project folder, it is there somewhere in a network folder or in a local machine for which the path is \\networkcomputer\sharedrive\parentfolder\demo.docx or like D:\Documents\demo.docx
Can I still load these documents into RadDocument?
Thanks,
Uday
All that is really needed to load a document is to be able to obtain a stream to its contents. Whether you will be able to get a stream to a file located in a local file system isn't related to RadDocument but rather to the way the Silverlight plugin restricts the user environment. One thing you may look into is OOB applications - there's a tutorial on silverlight.net.
Greetings,
Ivailo
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>