UPDATED:
I fixed it. But now I want to know how can I change serializable namespace, making my created-by-code xml became like its created by Web browser, since I can't update promoted column value.
ORIGINAL POST:
Hello all,
First of all, I've read and learned a lot in infopathdev.com. And this is my 1st post.
Here is my situation :
1/ I have an infopath browsed-enable form which contain code-behind.Let's call it "FORM A"
2/ I'm trying to use this FORM A to create another form ( FORM B) in another Document Library in SharePoint.
3/ So far, my code can build and preview without any error, It's also create a form in another Document Library.
4/ But when I tried to upload this form to Central Administration ( due to full trust, admin approval for those code-behind ). I received an error : "Object reference not set to an instance of an object"
Other facts :
I'm using xsd.exe to create a class FORM B, then add it to my FORM A VSTA project.
My template FORM B :
-INV
--group MainBody
--------group Products
----------------textfield ProductsName
----------------textfield ProductsCAT
----------------interger Quantity
--------group FileAttachment
----------------FileAttachment Files
--group Hidden
My code in FORM A:
<Code>
INV inv = new INV();
inv.MainBody = new MainBody();
inv.MainBody.Products = new Products();
inv.MainBody.FileAttachment = new FileAttachment();
inv.Hidden = new Hidden();
string ProductsName = "Name 1";
string ProductsCAT = "Category 1";
int Quantity = 1;
inv.MainBody.Products.ProductsName = ProductsName;
inv.MainBody.Products.ProductsCAT = ProductsCAT;
inv.MainBody.Products.Quantity = Quantity;
MemoryStream myInStream = new MemoryStream();
string rFormSite = @"http://win-3n17kmdof3n/LIBRARY_B/";
string rTemplateLocation = @"http://win-3n17kmdof3n/LIBRARY_B/Forms/template.xsn";
using (myInStream)
{
XmlSerializer serializer = new XmlSerializer(typeof(INV));
XmlTextWriter writer = new XmlTextWriter(myInStream, Encoding.UTF8);
string rInstruction = "name=\"urn:schemas-microsoft-com:office:infopath:LIBRARY_B:-myXSD-2013-08-01T10-04-54\"";
rInstruction += " solutionVersion=\"1.0.0.238\" productVersion=\"14.0.0.0\" PIVersion=\"1.0.0.0\" href=\"" + rTemplateLocation + "\"";
writer.WriteProcessingInstruction("mso-infoPathSolution", rInstruction);
writer.WriteProcessingInstruction("mso-application", "progid=\"InfoPath.Document\" versionProgid=\"InfoPath.Document.3\"");
serializer.Serialize(writer, inv);
using (SPSite site = new SPSite(rFormSite))
{
using (SPWeb webs = site.OpenWeb())
{
webs.Files.Add(rFormSite + RandomfilenameFunc() + ".xml", myInStream);
}
}
}
</Code>
Thank you,
Update :
Instead of add the class to project. I've copied all the code in the class created by xsd.exe and pasted it into FormClass.cs
Somehow I can upload the form now. But when the code of that button is executed, Infopath thrown an error :"There has been an error while processing the form. - LogID 5337"