i would like to open my word document placed it on server(http://www.myserver.com/docs/test.doc) into rich textbox control
my purpose is client can view the word document and edit and save it on the server..without saving it on local
Regards
Venu
23 Answers, 1 is accepted
Doc import and export is not supported. For a list of the supported file formats and the way a document can be created from data in a specific format, please refer to this article.
When it comes to persisting the documents on the server, you can find two examples (one using XamlDataProvider and one working with DocxFormatProvider) in this forum post.
Iva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I'm attempting to create a similar function but my data (.docx) files will come from the App_Data folder.
I tried looking at the sample but found it very confusing because it seems to have several examples built into it. Perhaps it was used to demonstrate several solutions AND at the same time show how to load a .docx file into RadEditor?
Do you know if there are any other examples available that clearly show how to load a .docx file from a server folder (like app_data)?
Any help would be greatly appreciated.
Thanks!
~ Dave
Please find attached an example showing how a file on the server can be loaded in RadRichTextBox using WebClient.
However, the file cannot be put in the App_Data folder of the Web project, as the server restricts the access to it. This topic is discussed in greater detail in this Silverlight forum.
I hope this helps.
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Thanks for the reply and demo project. I'll review them and let you know how it goes. One thing I'm confused about is your statement about the App_Data folder. You say that the file cannot be put in there and then you pass along a link that says the file CAN be put in there.
Perhaps I'm missing something? Is the method of using WebClient the issue? If so, then I'll have to find another way because I need to use the App_Data folder.
Please let me know and thanks!
~ Dave
What I gathered from the forum in the link is that the App_data folder is reserved for use by the Web project and cannot be accessed from Silverlight using WebClient.
However, you can use WCF/RIA services as done in the two examples in this forum post - the ones you said you had reviewed, but found confusing. Actually, the examples do not deal with any task other than the storage and retrieving of documents on the Server.
The functionality of the demo is as follows:
1. The MainPage shows a RadRichTextBox and RadRichTextBoxRibbonUI, in a layout similar to the one in the TelerikEditor demo.
2. A listbox, which shows the headers of all Documents in the database. The selected document in the listbox gets shown in the editor.
3. Buttons for adding and deleting documents. Adding a new document in the database happens after a header for the document is specified in the additional RadWindow.
Could you try reviewing one of the demos again? More information on RIA services can be found here.
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
After reading your post I was able to understand the project better. Unfortunately the methods described in the project use a database to store the files.
Our project is storing the files as .docx files - not in the database but simply in the App_Data folder. If we were to store the files in a database then the method described in the demo project would work well.
The method I'm going to use will require me to setup a helper class to move some files around on the server but it will allow me to use the App_Data folder, or, any folder on any server. The connection string data will be kept in a database and the helper class will move the files as needed.
Here's the sample code given to me via my Telerik support ticket. It works very well and was easy to implement.
private void loadDOCX(string strFileName)
{
Uri url = new Uri("/" + strFileName + "", UriKind.RelativeOrAbsolute);
WebClient wc = new WebClient();
wc.OpenReadAsync(url);
wc.OpenReadCompleted += (s, args) =>
{
if (args.Error == null)
{
IDocumentFormatProvider formatProvider = DocumentFormatProvidersManager.GetProviderByExtension(".docx");
this.radRichTextBox1.Document = formatProvider.Import(args.Result);
}
};
}
Unless I've missed some show stopping detail I'll work with this code for a while. After the dust settles on this project perhaps I'll look for a better solution.
Thank you very much for your help!
~ Dave
So, perhaps you have a suggestion for me... I'm able to retrieve my files with the method I described earlier, but, I did have to give up the App_Data folder.
Now I'm trying to save my files back to the server and find that the WebClient isn't working as I'd hoped. Here's what I have so far that is not working;
private void exportDocx()
{
Uri url = new Uri("/AppData/Alpha/" + app.strServerName + "/India/November/" + app.strBinFilename + "", UriKind.RelativeOrAbsolute);
WebClient wc = new WebClient();
DocxFormatProvider provider = new DocxFormatProvider();
MemoryStream output = new MemoryStream();
provider.Export(this.radRichTextBox1.Document, output);
wc.AllowWriteStreamBuffering = true;
wc.OpenWriteAsync(url, null, output);
wc.OpenWriteCompleted += (s, args) =>
{
context.saveDocx(app.strServerName, app.strBinFilename);
MessageBox.Show("Upload Complete...");
};
}
Please let me know what you think I could do to get this working.
Thank you!
~ Dave
Thanks to your help I've been able to get my files to download and upload... but only on my local dev pc. I suspect that I have a permissions issue? Not sure. I'm not changing domains and I do use the radUpload control without any issue.
Here's what's working on my dev pc;
Uri url = new Uri("/AppData/Alpha/" + app.strServerName + "/India/November/" + app.strBinFilename + "", UriKind.RelativeOrAbsolute);
WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
wc.OpenReadAsync(url);
For some reason the code that runs great on my dev pc fails on the server... so, thought I'd ask to see if anyone has any ideas as to what might be going wrong or what I should be looking for. Also, please note that I'm using a folder called "AppData" to hold more folders and files. This is not the same as "App_Data", which is of course locked.
Please let me know and thanks!
~ Dave
Just in case anyone is curious, here's the other piece of the code I'm using;
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
this.radRichTextBox1.Document = new DocxFormatProvider().Import(e.Result);
context.deleteDocx(app.strServerName, app.strBinFilename);
convertSmartDocxTemplate();
e.Result.Close();
}
Thanks,
~ Dave
Does the WebClient Class have to run on a server with the trust level = Full?
My hosting company said that the server I'm running my Silverlight 4 app from is in "Medium Trust" mode (their default). They said in some cases our sites to run in Full Trust mode.
Since my file isn't downloading from our test server I thought that maybe I was having a security issue? You know the ole saying - "It works on my pc...". Well, that is the case here. It works on my pc. WebClient downloads my file as expected. But it doesn't work on my server.
In case you'd like to see the error I'm getting I've attached a screen shot of it.
Please let me know and thanks!
Dave
this.radRichTextBox1.Document = formatProvider.Import(e.Result);
It works as expected on my pc but fails on the server. Could it be SSL?
Please let me know and thanks,
~ Dave
After applying some error trapping (always a good thing) I was able to finally get a message that I could understand.
Turns out it was a path issue. My original path string did NOT include the ".." in front. And the code worked fine on my dev pc.
But once I placed in on the server it failed. Here's what the new uri string looks like with the ".." on front... and it works.
Uri url = new Uri("../AppData/Alpha/" + app.strServerName + "/India/November/" + app.strBinFilename + "", UriKind.RelativeOrAbsolute);
So, case closed!
~ Dave
I have one problem in radRichTextBox that i am able to retrieve the document but not able to save that file back on server.
I tried the above Code but didn't any success and When Click the Save button that document should be Save on Server not on client machine.
please provide me Example ASAP.
I am really thankful to you.
Saving a .docx file was confusing to me but with the help of Telerik support, I was able to get a function working.
What I did was rewire the small 'save' icon that is visible in the top most toolbar of the RichTextBox. I pointed it to a new function that simply exports my .docx file to the server.
The real trick was understanding that you don't "export" directly to the server. You're working with a file that's in memory. You have to take that file 'as a stream' and pass it to a RadUpload control.
You'll also need to pass in your file name and target directory and then tell the upload control to begin uploading.
Here's the code snippet that does most of the work;
private void exportDocx()
{
DocxFormatProvider provider = new DocxFormatProvider();
MemoryStream stream = new MemoryStream();
provider.Export(this.radRichTextBox1.Document, stream);
stream.Position = 0L;
RadUploadSelectedFile f = new RadUploadSelectedFile(stream, app.strBinFilename);
this.radUpload2.TargetFolder = "AppData/Alpha/" + app.strServerName + "/India/November";
this.radUpload2.CurrentSession.SelectedFiles.Add(f);
this.radUpload2.PrepareSelectedFilesForUpload();
this.radUpload2.StartUpload();
}
I hope this helps,
~ Dave
First of all thanks to you.
Actually our client requirement is that the, user can Edit/View the document online Without save it on his machine and if it update that document then that document should be save on Server.
I have tried your solution but there is a error that "file operation not permitted access to path is denied" on the below code highlighted in yellow line
private void Save_Click(object sender, RoutedEventArgs e)
{
// DocxFormatProvider provider = new DocxFormatProvider();
IDocumentFormatProvider provider = new DocxFormatProvider();
MemoryStream stream = new MemoryStream();
provider.Export(this.editor.Document,stream);
stream.Position = 0L;
FileInfo objfile = new FileInfo("/Ashd_1.docx");
string extension = objfile.Extension;RadUploadSelectedFile f = new RadUploadSelectedFile(objfile);
RadUpload radUpload2 = new RadUpload();
radUpload2.TargetFolder = "/New";
radUpload2.CurrentSession.SelectedFiles.Add(f);
radUpload2.PrepareSelectedFilesForUpload();
radUpload2.StartUpload();
}
Please tell me how can i solve this issue.
Regards,
Ashish
Did you try to work with my code snippet before changing it? I'm curious if it will work for you. It would be nice to see that something works. Also, it appears that your code may not work because you're not converting the objfile to a stream... and I think that is an important part of the process.
I let the richtexteditor handle that part for me by simply exporting the file to a stream. Once it's a stream the upload control can save it on the server.
If you start with a file thats on the local pc because your user wishes to view it then open it into the richtexteditor. Then, you can begin the process like I've setup with my code snippet. Use the export function to create the stream... then pass your file name to the upload control along with your stream.
I hope this helps,
~ Dave
I tried your code but there was a error when i Compile your code.
Below is your Code highlighted in green where i faced a issue.
private void exportDocx()
{
DocxFormatProvider provider = new DocxFormatProvider();
MemoryStream stream = new MemoryStream();
provider.Export(this.radRichTextBox1.Document, stream);
stream.Position = 0L;
RadUploadSelectedFile f = new RadUploadSelectedFile(stream,app.strBinFilename);
this.radUpload2.TargetFolder = "AppData/Alpha/" + app.strServerName + "/India/November";
this.radUpload2.CurrentSession.SelectedFiles.Add(f);
this.radUpload2.PrepareSelectedFilesForUpload();
this.radUpload2.StartUpload();
}
As RadUploadSelectedFile takes only one argument but have passed two argument here and what about app.strBinFilename . i didn't find any reference of that.
Please help me to solve that issue.
Thanks,
I apologize for not being clear on this. app.strBinFilename is a property I created to simply hold the file name of a binary file.
Change app.strBinFilename for another string variable and assign your file name to it. That's what the control is looking for... a file name (as a string).
~ Dave
P.S. I've attached a small screen shot showing my dev pc code... Intellisense shows two arguments. The second being a string.
Thanks for your Valuable Support.
But in my RadUploadSelectedFile object, it accepts only 1 argument not 2 argument.
Also Attached the screenshot same.
Kindly know which telerik component you are using.
i am using this version 2011.2.920.1040
Thanks,
I believe we added the overloaded constructor for the RadUploadSelectedFile class in the latest service pack (Q3 SP1 2011). It is not available in the version that you are using.
Greetings,
Alex Fidanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Thanks,
I'm currently using version Q3 - 2011.3.1323.1040. This version is one of the 'internal builds'.
~ Dave