You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i have sharepoint list where user populate some fields. i made event receiver that when user update some fields in document library is created document where inserting repeating data in table. i have problem. my code is
SPList list = web.Lists[sList];
// this always uses root folder
SPFolder folder = list.RootFolder;
SPFileCollection fcol = folder.Files;
// find the template url and open
string sTemplate = list.ContentTypes[sContentType].DocumentTemplateUrl;
SPFile spf = web.GetFile(sTemplate);
byte[] binFile = spf.OpenBinary();
// Url for file to be created
string destFile = fcol.Folder.Url + "/" + sFilename;
SPFile addedFile = fcol.Add(destFile, binFile);
SPItem newItem = addedFile.Item;
newItem.Update();
addedFile.Update();
SPQuery query = new SPQuery();
query.Query = "<Where><Eq>" + "<FieldRef Name='FileLeafRef' />" + "<Value Type='Text'>" + sFilename + "</Value>" + "</Eq>" + "</Where>";
SPListItemCollection collection = list.GetItems(query);
SPFile file = collection[0].File;
byte[] byteArray = file.OpenBinary();
using (MemoryStream memStr = new MemoryStream())
{
memStr.Write(byteArray, 0, byteArray.Length);
using (WordprocessingDocument doc = WordprocessingDocument.Open(memStr, true))
{
//create XML string matching custom XML part
MainDocumentPart main = doc.MainDocumentPart;
Table TabelaZapisnik = main.Document.Body.Descendants<Table>().First();
// Get the last row in the table.
TableRow Red = TabelaZapisnik.Elements<TableRow>().Last();
TableRow rowCopy = (TableRow)Red.CloneNode(true);
rowCopy.Descendants<TableCell>().ElementAt(0).Append(new Paragraph(new Run(new Text("1"))));
rowCopy.Descendants<TableCell>().ElementAt(1).Append(new Paragraph(new Run(new Text("Test1"))));
rowCopy.Descendants<TableCell>().ElementAt(2).Append(new Paragraph(new Run(new Text("Test2"))));
rowCopy.Descendants<TableCell>().ElementAt(3).Append(new Paragraph(new Run(new Text("Test3"))));
rowCopy.Descendants<TableCell>().ElementAt(4).Append(new Paragraph(new Run(new Text("Test4"))));
rowCopy.Descendants<TableCell>().ElementAt(5).Append(new Paragraph(new Run(new Text("Test5"))));
TabelaZapisnik.AppendChild(rowCopy);
// Remove the empty placeholder row from the table.
TabelaZapisnik.RemoveChild(Red);
// Save the changes to the table back into the document.
main.Document.Save();
//closing WordprocessingDocument automatically saves the document
}
}
//OpenXml kreiranje dokumenata - kraj
return true;
}
}
catch (SPException spEx)
{
// file already exists?
if (spEx.ErrorCode == -2130575257)
return false;
else
throw spEx;
}`
the created document from template in document library is created but he is not updated with values: Test1,Test2,Test3,Test4 and Test5.
i set breakpoint on 'SPListItemCollection collection = list.GetItems(query); SPFile file = collection[0].File;' and i receive file, like collection[0].File {1/ЗППС-2021-12-Дом здравља - Вождовац.docx}
i debugged main.Document.Save(); and i receive 'main.Document.Save() Expression has been evaluated and has no value void'
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
i have sharepoint list where user populate some fields. i made event receiver that when user update some fields in document library is created document where inserting repeating data in table. i have problem. my code is
`public bool CreateDocument(string sFilename, string sContentType, string sList, string id, string broj, string datum, string opis, string ponudjac, string ponudjacadresa, string ponudjacemail, string sektor, string sektormestorada, string subjektrevizije, string usluge, string akontacija, string udaljenostodsubjekta, string rukovodilac, string url)
{
try
{
SPSite site = new SPSite(url);
using (SPWeb web = site.OpenWeb())
{
the created document from template in document library is created but he is not updated with values: Test1,Test2,Test3,Test4 and Test5.
i set breakpoint on 'SPListItemCollection collection = list.GetItems(query); SPFile file = collection[0].File;' and i receive file, like collection[0].File {1/ЗППС-2021-12-Дом здравља - Вождовац.docx}
i debugged main.Document.Save(); and i receive 'main.Document.Save() Expression has been evaluated and has no value void'
Beta Was this translation helpful? Give feedback.
All reactions