C# to read XFA form data - Syncfusion - c#-4.0

every one, just updated syncfusion and Itextsharp library on Visual Studio 2022, got some errors.
before it worked for me well. will show you code.
codes are following:
//Load the existing XFA form
FileStream loadStream = new FileStream(sourceXfaPath, FileMode.Open);
PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(loadStream);
PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm;
FileStream exportStream = new FileStream(exportXfaXml, FileMode.Create);
//Export the XFA data
loadedForm.ExportXfaData(exportStream);
error message is following
The type 'PdfLoadedXfaForm' exists in both `Syncfusion.Pdf.Base, Version=20.4460.0.44, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89` and `Syncfusion.Pdf.Portable`, Version=20.4200.0.44, Culture=neutral,
so, just tried added some code Sycfusion.Pdf.Xfa.PdfLoadedXfaForm.
but it still shows me same error.

Related

Embedding Excel Add-Ins with OpenXml

My team is working on an Office 365 add-in for Excel, and as part of the project, we’re creating Excel documents through the GraphAPI with the end goal of having the add-in already setup for the document. We’re using the .NET OpenXml library to create the document before copying it through the GraphAPI.
We haven’t been able to find many resources for how to setup an add-in through OpenXml and have not been able to get anything working. The last thing we tried was copying the example we found here, but we couldn’t get it working. Does anyone know how to setup add-ins using the OpenXml library?
Note: the add-in is already in the Office Add-Ins store, and we have information like the AppSource ID.
Thank you!
We're actually about to publish a new sample around this scenario. The sample shows how to create an Excel document using OOXML, embed your add-in, and then upload the file to OneDrive. It also creates a Team chat that links to the file.
You can try out the sample here: Open data from your web site in a spreadsheet in Microsoft Teams
Or give us feedback on the PR: https://github.com/OfficeDev/PnP-OfficeAddins/pull/197
To answer your question about how to embed the add-in, you need to create a web extension section. I've copied the relevant code here. Note this is the same code from the Office-OOXML-EmbedAddin sample you already looked at. We reused it for the new sample. You can change the CUSTOM MODIFICATION section to provide any custom properties you want to your add-in when it opens.
// Embeds the add-in into a file of the specified type.
private void EmbedAddin(SpreadsheetDocument spreadsheet)
{
spreadsheet.DeletePart(spreadsheet.WebExTaskpanesPart);
var webExTaskpanesPart = spreadsheet.AddWebExTaskpanesPart();
CreateWebExTaskpanesPart(webExTaskpanesPart);
}
// Adds child parts and generates content of the specified part.
private void CreateWebExTaskpanesPart(WebExTaskpanesPart part)
{
WebExtensionPart webExtensionPart1 = part.AddNewPart<WebExtensionPart>("rId1");
GenerateWebExtensionPart1Content(webExtensionPart1);
GeneratePartContent(part);
}
// Generates content of webExtensionPart1.
private void GenerateWebExtensionPart1Content(WebExtensionPart webExtensionPart1)
{
// Add web extension containg Id for Script Lab add-in
We.WebExtension webExtension1 = new We.WebExtension() { Id = "{635BF0CD-42CC-4174-B8D2-6D375C9A759E}" };
webExtension1.AddNamespaceDeclaration("we", "http://schemas.microsoft.com/office/webextensions/webextension/2010/11");
// Add store information for Script Lab add-in
We.WebExtensionStoreReference webExtensionStoreReference1 = new We.WebExtensionStoreReference() { Id = "wa104380862", Version = "1.1.0.0", Store = "en-US", StoreType = "OMEX" };
We.WebExtensionReferenceList webExtensionReferenceList1 = new We.WebExtensionReferenceList();
We.WebExtensionPropertyBag webExtensionPropertyBag1 = new We.WebExtensionPropertyBag();
// Add the property that makes the taskpane visible.
We.WebExtensionProperty webExtensionProperty1 = new We.WebExtensionProperty() { Name = "Office.AutoShowTaskpaneWithDocument", Value = "true" };
webExtensionPropertyBag1.Append(webExtensionProperty1);
// CUSTOM MODIFICATION BEGIN
// Add the property that specifies the snippet to import.
string snippetToImportValue = string.Format("{{\"type\":\"gist\",\"id\":\"{0}\"}}", "{72189570-AE11-4207-9DEE-C8BDE4B83188}");
We.WebExtensionProperty webExtensionProperty2 = new We.WebExtensionProperty() { Name = "SnippetToImport", Value = snippetToImportValue };
webExtensionPropertyBag1.Append(webExtensionProperty2);
// CUSTOM MODIFICATION END
We.WebExtensionBindingList webExtensionBindingList1 = new We.WebExtensionBindingList();
We.Snapshot snapshot1 = new We.Snapshot();
snapshot1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
webExtension1.Append(webExtensionStoreReference1);
webExtension1.Append(webExtensionReferenceList1);
webExtension1.Append(webExtensionPropertyBag1);
webExtension1.Append(webExtensionBindingList1);
webExtension1.Append(snapshot1);
webExtensionPart1.WebExtension = webExtension1;
}
// Generates content of part.
private void GeneratePartContent(WebExTaskpanesPart part)
{
Wetp.Taskpanes taskpanes1 = new Wetp.Taskpanes();
taskpanes1.AddNamespaceDeclaration("wetp", "http://schemas.microsoft.com/office/webextensions/taskpanes/2010/11");
Wetp.WebExtensionTaskpane webExtensionTaskpane1 = new Wetp.WebExtensionTaskpane() { DockState = "right", Visibility = true, Width = 350D, Row = (UInt32Value)4U };
Wetp.WebExtensionPartReference webExtensionPartReference1 = new Wetp.WebExtensionPartReference() { Id = "rId1" };
webExtensionPartReference1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
webExtensionTaskpane1.Append(webExtensionPartReference1);
taskpanes1.Append(webExtensionTaskpane1);
part.Taskpanes = taskpanes1;
}

Which Active Reports export type works with the HTML5 JavaScript viewer

I have a custom Active Reports server implemented in an httphandler, which can generate and export reports in the various formats available using the AR run-time ( excel, html, PDF, ... ). I'm now trying to use the JavaScript HTML5 viewer but it doesn't seem to be compatible with with any of the obvious export formats. The documentation and examples all show using the HTML5 viewer with the actual Active Reports server product and there are no examples for using it with a custom report service.
Client Code:
var viewer = GrapeCity.ActiveReports.Viewer(
{
element: '#reportViewer',
report: {
id: "report1.rdlx"
},
reportService: {
url: /MyCustomReportService/reports.mrs?msg={....}
},
uiType: 'desktop'
});
Server Code:
request.context.Response.ContentType = "image/gif";
MemoryStream memoryStream = new MemoryStream();
report.Document.Save(memoryStream);
context.Response.BinaryWrite(memoryStream.ToArray());
also tried
request.context.Response.ContentType = "message/rfc822";
HtmlExport html = new HtmlExport();
html.OutputType = HtmlOutputType.DynamicHtml;
MemoryStream memoryStream = new MemoryStream();
html.Export(report.Document, memoryStream);
request.context.Response.BinaryWrite(memoryStream.ToArray());
From what I understand, you have two requirements :
(Please refer to my forum posts for each of the below requirements)
>>>> Using the HTML5Viewer with a CustomReportService
http://arhelp.grapecity.com/groups/topic/rdlx-and-web-config/#post-658924
http://arhelp.grapecity.com/groups/topic/crystal-report-object-data-source-html5/#post-660665
>>>> Implementing Custom Export in HTML5Viewer
http://arhelp.grapecity.com/groups/topic/csv-export-from-html5-viewer/#post-658376
http://arhelp.grapecity.com/groups/topic/html5-viewer-export-to-xlsx/#post-657866
http://arhelp.grapecity.com/groups/topic/export-to-rtf-using-html5-viewer/#post-656001
Let me know if that does not works for you or you have any further issues.
Regards,
Reema

Exception when open excel: File contains corrupted data

I am trying to read an excel with OpenXML.
What I did is simply as following:
private WorkbookPart wbPart = null;
private SpreadsheetDocument document = null;
public byte[] GetExcelReport()
{
byte[] original = File.ReadAllBytes(this.originalFilename);
using (MemoryStream stream = new MemoryStream())
{
stream.Write(original, 0, original.Length);
using (SpreadsheetDocument excel = SpreadsheetDocument.Open(stream, true))
{
this.document = excel;
this.wbPart = document.WorkbookPart;
UpdateValue();
}
stream.Seek(0, SeekOrigin.Begin);
byte[] data = stream.ToArray();
return data;
}
}
I initialized this.originalFilename in the constructor. It is the filename ended with '.xlsx' which i created with excel 2010.
But this line of code
using (SpreadsheetDocument excel = SpreadsheetDocument.Open(stream, true))
gives the exception: Message: System.IO.FileFormatException: File contains corrupted data.
The StackTrace:
Does anyone know how to solve this problem? At the beginning, I didn't use the Stream, I just use SpreadsheetDocument.Open(filename, true). However, it turns out to be exactly the same exception.
I've tried to create a new .xlsx file, but it's still the same.
There is a MSDN page which describes the process of reading and writing Excel file using stream and open xml SDK.
http://msdn.microsoft.com/en-us/library/office/ff478410.aspx
Try extracting the document contents through zip application and check whether you are getting the standard folders inside like xl,docProps and _rels etc.,
This is a method to find whether the package is properly packaged as archive or not.
Hope this helps.

Upload Excel in flex

I want to upload excel file and show the content of uploaded excel file data grid. Everything is going well. But when i convert the the content in the form of byteArray in excel sheet format with the help of loadFromByteArray() function then system is giving me error as "Cannot access a property or method of a null object reference".
Here is my code to upload excel content:
protected function browseExcelFile(event:MouseEvent):void
{
excFileRef = new FileReference();
excFileRef.addEventListener(Event.SELECT, onSelect);
excFileRef.addEventListener(Event.COMPLETE, onComplete);
var fileFilter:FileFilter = new FileFilter("Excel (.xls)", "*.xls");
excFileRef.browse([fileFilter]);
}
private function onSelect(event:Event):void {
excelFileName.text = excFileRef.name;
excFileRef.load();
}
private function onComplete(event:Event):void {
excelFileName.text = excFileRef.name;
exceldataInByte = new ByteArray();
exceldataInByte = event.currentTarget.data;
if(exceldataInByte.length > 0){
var excObj:ExcelFile = new ExcelFile();
excObj.loadFromByteArray(exceldataInByte); /* this line give error */
var sheet:Sheet = excObj.sheets[0];
}
}
I dont know why this error occuring, i have searched on many sites but everywhere everyone posted the same way as i have done to upload excel but my code gives me error.
Please tell me why this error occur?
EDIT: After viewing this preview (http://activetuts.s3.amazonaws.com/tuts/169_as3xls/1/preview.html) I realized that this excel import tool only works with spreadsheets who only have 2 columns of data, regardless of how many columns your datagrid has. After trying to load an .xls file of only two columns into my own test app, it is working as expected.
I believe I recreated your error.
Here is the line that threw the error:
excObj.loadFromByteArray(exceldataInByte); /* this line give error */
Here is the error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.as3xls.xls::ExcelFile/dimensions()[/...com/as3xls/xls/ExcelFile.as:619]
at Function/http://adobe.com/AS3/2006/builtin::call()
at com.as3xls.xls::ExcelFile/loadFromByteArray()[/...com/as3xls/xls/ExcelFile.as:309]
at stackoverflow/onComplete()[C:\...\src\stackoverflow.mxml:47]
Here is the line which is throwing the error in the swc (line 619): https://code.google.com/p/as3xls/source/browse/trunk/src/com/as3xls/xls/ExcelFile.as#619
I suggest you checkout the source code into your workspace from here (https://code.google.com/p/as3xls/source/checkout), and debug to find what is broken.

unable to change the account reference inside the contact using sdk in crm2011

I am unable to change the client by updating the contact using crm 2011 sdk.Here is the code i am using to do that :
Entity contact = new Entity();
contact.LogicalName = "contact";
contact.Attributes = new AttributeCollection();
EntityReference clientLookup = new EntityReference();
clientLookup.Id = NewClientBId;
clientLookup.LogicalName = "account";
contact.Attributes.Add("parentcustomerid", clientLookup);
contact.Attributes.Add("contactid", workItem.Id);
SynchronousUtility.UpdateDynamicEntity(CrmConnector.Service, contact);
The code runs fine without any error but when i go to web portal and check the record ,it still points to the old account though updated the modofication time stamp.I also checked the sql profiler query which shows up as below :
exec sp_executesql N'update [ContactBase] set
[ModifiedOn]=#ModifiedOn0, [ModifiedBy]=#ModifiedBy0,
[ModifiedOnBehalfBy]=NULL where ([ContactId] =
#ContactId0)',N'#ModifiedOn0 datetime,#ModifiedBy0
uniqueidentifier,#ContactId0
uniqueidentifier',#ModifiedOn0='2013-07-04
09:21:02',#ModifiedBy0='2F8D969F-34AB-E111-9598-005056947387',#ContactId0='D80ACC4E-A185-E211-AB64-002324040068'
as can be seen above the column i have updated is not even there in the set clause of the update query.Can anyone help me with this ?
I tested your code and it works:
Entity contact = new Entity();
contact.LogicalName = "contact";
contact.Attributes = new AttributeCollection();
EntityReference clientLookup = new EntityReference();
clientLookup.Id = new Guid("3522bae7-5ae5-e211-9d27-b4b52f566dbc");
clientLookup.LogicalName = "account";
contact.Attributes.Add("parentcustomerid", clientLookup);
contact.Attributes.Add("contactid", new Guid("16dc4143-5ae5-e211-9d27-b4b52f566dbc"));
As you can see I used existing Id in my environment, and to perform the update I used
service.Update(contact);
Reasons why your code is not working:
NewClientBId is not the right account Guid
workItem.Id is not the right contact Guid
the function SynchronousUtility.UpdateDynamicEntity has errors

Resources