Hi I´m trying get barcode value from an uploaded file, but getbarcodevalue() not works, library has enabled barcode. error say me return value is null. Here is the code, any idea??
public void button_Clicked(object sender, ClickedEventArgs e)
{
XPathNavigator attachmentNav = MainDataSource.CreateNavigator();
// Get the base64 encoded attachment
string attachedFile = attachmentNav.SelectSingleNode("//my:Adjunto", NamespaceManager).Value;
attachmentNav = attachmentNav.SelectSingleNode("//my:Adjunto", NamespaceManager);
// Delete the encoded file form XML form
attachmentNav.InnerXml = string.Empty;
// Convert the base64 encoded string into a byte array
InfoPathAttachmentDecoder decoder = new InfoPathAttachmentDecoder(attachedFile);
byte[] attachment = decoder.DecodedAttachment;
string fileName = decoder.Filename;
// Add the file as an attachment to the SharePoint list item
using (SPSite site = SPContext.Current.Site)
{
if (site != null)
{
using (SPWeb web = site.OpenWeb())
{
// Turn on AllowUnsafeUpdates on the site
web.AllowUnsafeUpdates = true;
// Add the attached document to "Documents" library
SPFolder lib = web.GetFolder("ADJUNTOS");
SPFile file = lib.Files.Add(fileName, attachment, true);
file.Item.Update();
file.Update();
// Get file url
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(MainDataSource.CreateNavigator().OuterXml);
Uri url = new Uri(new Uri(web.Url), file.Url);
//Get barcode value
SPWeb spwCurrent = SPContext.Current.Web;
SPListItem documentX = spwCurrent.Lists["ADJUNTOS"].Items[file.UniqueId];
string Bar_Code= Barcode.GetBarcodeValue(documentX);
MainDataSource.CreateNavigator().SelectSingleNode("//my:campo", NamespaceManager).SetValue(Bar_Code);
// Turn off AllowUnsafeUpdates on the site
web.AllowUnsafeUpdates = false;
// Close the connection to the site
web.Close();
}
// Close the connection to the site collection
site.Close();
}
}
}