Get image name in Nopcommerce

I want to create XML with a list of products from a Nopcommerce site. Since the image is in binary format, I cannot find a way to get only the image name (I only need the image name so that it does not appear on the image) any idea? my missing code is in the line / 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(); 
+7
c # nopcommerce
source share
2 answers

If I am not mistaken, one product may have several images, perhaps you need to use a loop for this.

Since you have product identifiers, you can use the image service to get a seo image.

The GetPicturesByProductId image GetPicturesByProductId provides you with a list of photos, and you just need to get it seoname

 var pictures = _pictureService.GetPicturesByProductId(items.id) foreach(item in pictures) { writer.WriteStartElement("IMAGE"); writer.WriteString(item.SeoFilename); writer.WriteEndElement(); } 
+3
source share

Xml does not support binary data, you need to convert it to text format because Xml is used as a massage format. Do you need smth. eg:

 string text = System.Text.Encoding.UTF8.GetString(data); 

Here is the link: binary-xml

 byte[] binaryData; try { binaryData = System.Convert.FromBase64String(base64String); } 

This is an alternative for XmlReader. Check out this link: alternative

The declaration, if you adhere to XmlReader, will try to implement this:

 writer.WriteStartElement("Image"); writer.WriteBase64(fileData[1], 0, fileData[1].Length); 

Also see this: stack discussion

I'm not sure if this will help you. Not much has been experienced, but I'm glad if this helps.

+2
source share

All Articles