I want to create XML with list of products from Nopcommerce website. Because the image is in binary i cant find a way to get only the name of the image (i only need the image name not to display it on Image) any idea? my missing code is in the line of /images/thumbs/
topsystemDataClassesDataContext db = new topsystemDataClassesDataContext();
XmlTextWriter writer = new XmlTextWriter(path + "/Products_" + catid + ".xml", System.Text.Encoding.UTF8);
writer.WriteStartDocument(true);
writer.Formatting = Formatting.Indented;
writer.Indentation = 2;
writer.WriteStartElement("store");
//CREATE-SCREENS
var allProducts = (from p in db.Product_Category_Mappings
where p.CategoryId == catid
join s in db.Products
on p.ProductId equals s.Id
join im in db.Product_Picture_Mappings
on p.ProductId equals im.ProductId
join imag in db.Pictures
on im.PictureId equals imag.Id
select new
{
s.Name,
s.Id,
s.Price,
s.ShortDescription,
s.BackorderModeId,
im.PictureId,
imag.PictureBinary
}).ToList();
foreach (var item in allProducts)
{
writer.WriteStartElement("product");
writer.WriteStartElement("PRODUCT_URL");
writer.WriteString("http://www.topsystems.co.il/Product.aspx?ProductId=" + item.Id);
writer.WriteEndElement();
writer.WriteStartElement("product_name");
writer.WriteString(item.Name);
writer.WriteEndElement();
writer.WriteStartElement("MODEL");
writer.WriteString(item.BackorderModeId.ToString());
writer.WriteEndElement();
writer.WriteStartElement("CATALOG_NUMBER");
writer.WriteString("0");
writer.WriteEndElement();
writer.WriteStartElement("DETAILS");
writer.WriteString(item.ShortDescription);
writer.WriteEndElement();
writer.WriteStartElement("CURRENCY");
writer.WriteString("ILS");
writer.WriteEndElement();
writer.WriteStartElement("PRICE");
writer.WriteString(item.Price.ToString());
writer.WriteEndElement();
writer.WriteStartElement("SHIPMENT_COST");
writer.WriteString("0");
writer.WriteEndElement();
writer.WriteStartElement("DELIVERY_TIME");
writer.WriteString("3");
writer.WriteEndElement();
writer.WriteStartElement("MANUFACTURER");
writer.WriteString("ללא");
writer.WriteEndElement();
writer.WriteStartElement("WARRANTY");
writer.WriteString("ללא");
writer.WriteEndElement();
writer.WriteStartElement("IMAGE");
writer.WriteString("http://www.topsystems.co.il/content/images/thumbs/");
writer.WriteEndElement();
writer.WriteStartElement("TAX");
writer.WriteString("0");
writer.WriteEndElement();
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/xml";
Response.WriteFile(Server.MapPath("~/zap/Products_" + catid + ".xml"));
Response.Flush();
Response.End();
Xml does not support binary data, you have to convert it to a text format because Xml is used as a massage format. You need smth. like this:
Here is the link: binary-xml
This here is an alternative for XmlReader. Check this link: alternative
Ad if you are sticking with XmlReader try to implement this:
Also see this: stack-discussion
I'm not sure if this will help you. Not experienced with this so much but I'm glad if this will be of any help