This is a migrated thread and some comments may be shown as answers.

[Solved] Print a document through URL/Path as Argument.

5 Answers 148 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
udaybhaskar
Top achievements
Rank 1
udaybhaskar asked on 01 Aug 2011, 06:27 AM

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

Sort by
0
Vesko
Telerik team
answered on 03 Aug 2011, 09:38 AM
Hello Udaybhaskar,

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 >>

0
udaybhaskar
Top achievements
Rank 1
answered on 03 Aug 2011, 10:02 AM

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

 

0
Vesko
Telerik team
answered on 03 Aug 2011, 11:46 AM
Hello Udaybhaskar,

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);
        }
    };
}
It will opens a document, located in the root folder of your application and loads it in a RadRichTextBox.
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 >>

0
udaybhaskar
Top achievements
Rank 1
answered on 03 Aug 2011, 12:38 PM

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

0
Ivailo Karamanolev
Telerik team
answered on 08 Aug 2011, 10:23 AM
Hello Udaybhaskar,

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 >>

Tags
RichTextBox
Asked by
udaybhaskar
Top achievements
Rank 1
Answers by
Vesko
Telerik team
udaybhaskar
Top achievements
Rank 1
Ivailo Karamanolev
Telerik team
Share this question
or