Casey Plummer
Casey Plummer

Reputation: 3068

How do I programmatically set configuration for the ImageResizer SQLReader plugin v4?

I was previously using v3 of ImageResizer but am now trying to use v4.

See: http://imageresizing.net/docs/v4/plugins/sqlreader

I need to programmatically set the several config options for the SQLReader plugin. I had this previous code, but it no longer works, stating that the type SqlReaderSettings could not be found:

        // SqlReader Plugin
        var fileSettings = new SqlReaderSettings
        {
            ConnectionString = ApplicationConfigurationContext.Current.DefaultSiteSqlConnectionString,
            PathPrefix = "~/Images",
            StripFileExtension = true,
            ImageIdType = SqlDbType.UniqueIdentifier,
            ImageBlobQuery = ???,
            ModifiedDateQuery = ???,
            ImageExistsQuery = ???,
            CacheUnmodifiedFiles = true,
            RequireImageExtension = true
        };

I cannot use the web.config file to store some of these settings. Specifically the connection string may change at run-time, and cannot be stored un-encrypted in the web.config file due to company policy.

Thanks for the help.


Update: This is the code I now use. I did not add in this plugin from the Web.config as it would be redundant.

        new SqlReaderPlugin
        {
            ConnectionString = ApplicationConfigurationContext.Current.DefaultSiteSqlConnectionString,
            ImageIdType = SqlDbType.VarChar,
            QueriesAreStoredProcedures = true,
            ModifiedDateQuery = "procFileImageResizerSelectTimestamps",
            ImageBlobQuery = "procFileImageResizerSelectData",
            ExposeAsVpp = true,
            VirtualFilesystemPrefix = filesUri,
            RequireImageExtension = true,
            StripFileExtension = true,
            CacheUnmodifiedFiles = true

        }.Install(Config.Current);

Upvotes: 0

Views: 87

Answers (1)

Lilith River
Lilith River

Reputation: 16468

You can replace SqlReaderSettings with SqlReaderPlugin directly; it no longer uses a separate settings class. Nearly all the class members should be the same, so just change the name of the class you are initializing.

Upvotes: 1

Related Questions