Will this work to delete pictures images from the server?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hello,

I am using nopCommerce 3.90 with source.

Our Pictures are stored into...file system

We have over 86,000 images in /Content/Images, /Content/Images/Thumbs/000, /Content/Images/Thumbs/001, /Content/Images/Thumbs/002.

I want to get rid of a lot of those images by using the following processing:


List<int> productList = new List<int>()
    {
        1,
        2,
        3
    };

foreach (var prodId in productList)
    {
        IList<ProductPicture> prodPictureList = _productService.GetProductPicturesByProductId(prodId);

        foreach (var prodPicture in prodPictureList)
        {
            _productService.DeleteProductPicture(prodPicture);
        }

    }


Naturally productList will be bigger from another source.

Will the _productService.DeleteProductPicture(prodPicture); delete the images from the server?

Or, am I on the wrong track?

Any help would be gratefully appreciated.

Thanks,
Tony
6 years ago
Only deletes it from the database. Not from the file system.
6 years ago
Get full URL of Picture using by picture service and delete it from your directory.

if(File.Exists(picturePath))
{
     File.Delete(picturePath);
}


Hope this will help to you.
6 years ago
Thanks to Raju and calacula for their help.

This did it for me:

IList<ProductPicture> productPictureList = _productService.GetProductPicturesByProductId(productId);

foreach (var productPicture in productPictureList)
{
    if (productPicture == null)
        throw new ArgumentException("No product picture found with the specified id");

    var pictureId = productPicture.PictureId;
    _productService.DeleteProductPicture(productPicture);

    var picture = _pictureService.GetPictureById(pictureId);
    if (picture == null)
        throw new ArgumentException("No picture found with the specified id");
    _pictureService.DeletePicture(picture);
}


Thanks,
Tony
6 years ago
Sound Great !!
And thanks for code example.
6 years ago
rajupaladiya wrote:
Sound Great !!
And thanks for code example.


Raju,

You are welcome.

I'm glad that I can help somebody.  I have received much help in these forums and always wished I could answer questions for other posters.

Thanks,
Tony
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.