Hi Marwen
Out the box there is no way to display the contents of a file (from a DB) on a smartform. I think you would need to develop a custom control do this - I dont think I have ever seen one on the K2 Market.
OK. My environment is little bit different than yours but I thought of sharing with you. Instead of saving pdf file in database, we save in the Sharepoint document library, so we have a document URL of the sharepoint library. If you can somehow findout the URL of the pdf document in the database, I think you can view the pdf file in the smartform with little trick.
1. Create a data-label in the smartform, name it Data Link.
2. In its properties window, click on the [...] of the style and create ConcatLink expression (attached) and assign to it.
or
2. you can set the properties of the Data Link control on the Form Rule.
3.Check the literal in both the case.
Hi
thank you for your answers,
I solved this need by developping a simple asp.net page which connects to my smart object and passing to it the id of the element and get the file stored in xml format with the file content in base64.
the asp page renders a pdf viewer then i use K2 action to set the url of the content control to the url of the viewer with its ID
thank you all
here is the code used
SmartProperty fileMemo = smartObject.Propertiest"AttachementFile"];
// read the return properties of the SmartObject
if (fileMemo.Value != null)
{
var doc = new System.Xml.XmlDocument();
doc.LoadXml(fileMemo.Value);
var fileAsBase64 = doc.SelectSingleNode("/file/content").InnerText;
byte ] data = Convert.FromBase64String(fileAsBase64);
Response.ClearContent();
Response.OutputStream.Write(data, 0, data.Length);
Response.Flush();
Response.ContentType = "application/pdf";
}
Hi
Please when we run this code as a web form in visual studio, we get the following errors on debugging;
Error 3 The type or namespace name 'SmartProperty' could not be found (are you missing a using directive or an assembly reference?) c:usersk2_servicedocumentsvisual studio 2013Projects estwebapp estwebappPreview.aspx.cs *personal details removed* testwebapp
Error 4 The name 'smartObject' does not exist in the current context c:usersk2_servicedocumentsvisual studio 2013Projects estwebapp estwebappPreview.aspx.cs *personal details removed* testwebapp
Any help please?
Thank you
Here is a simple way that will work with K2 Five and later, in both on-premise and cloud versions. You won't need to download files, modify brokers, use fancy JavaScript, or bring SharePoint into the picture.
- Enable OData services in the Management portal.
- Expose the SmartObject that has the physical file saved in it.
- Set the URL of the Content Viewer control to the field of the SmartObject, after you've queried it using the OData query syntax. Here is an example of a query like that:
https://YourK2Server/api/odata/resources/YourSmartObject(YourRecordID)/AttachmentFileFieldName
WHERE- YourK2Server is the name of your K2 Server;
- YourSmartObject is the name of your SmartObject;
- YourRecordID is the numeric ID of your record, e.g. 1, 2, 333, etc; and
- AttachmentFileFieldName is the name of the field in the SmartObject that stores the File Attachment.
Here is a working example, I've just changed the server name:
https://stevesk2server.com/api/odata/resources/UncategorisedInvoices(45)/AttachedPDF
In my case, the record was returned via
https://k2dev/api/odata/v3/ONRLogs(1045)
but the attachment was returned with
https://k2dev.lifeflight.org.au/api/odata/resources/ONRLog(1045)/PDF
Notice two changes, ONRLogs vs ONRLog and odata/v3 vs odata/resources.
Hi.
Thank you for sharing information. I have tried and it is not working with .msg(outlook) file.
is there a way to get link for the .msg file to open in browser or any IIS configuration needs to be done?
Thanks in advance.
Regards,
Thriveni
Just FYI, I know this post is 2 years old, but I tried this method today and it works REALLY slick.
Soberware wrote:
Here is a simple way that will work with K2 Five and later, in both on-premise and cloud versions. You won't need to download files, modify brokers, use fancy JavaScript, or bring SharePoint into the picture.
- Enable OData services in the Management portal.
- Expose the SmartObject that has the physical file saved in it.
- Set the URL of the Content Viewer control to the field of the SmartObject, after you've queried it using the OData query syntax. Here is an example of a query like that:
https://YourK2Server/api/odata/resources/YourSmartObject(YourRecordID)/AttachmentFileFieldName
WHERE - YourK2Server is the name of your K2 Server;
- YourSmartObject is the name of your SmartObject;
- YourRecordID is the numeric ID of your record, e.g. 1, 2, 333, etc; and
- AttachmentFileFieldName is the name of the field in the SmartObject that stores the File Attachment.
Here is a working example, I've just changed the server name:
https://stevesk2server.com/api/odata/resources/UncategorisedInvoices(45)/AttachedPDF
Any tips on how to get this to display a specific page? So if in the document you have 10 pages but your users only need to view page 2, is there any way to adjust the URL to display only the relevant page?
Any help with this will be much appreciated.
Hi,
Is there any possibility to achieve the PDF View instead of OData SMO ?