Welcome to the Tridion community Vinoth!
You may specify any existing SG in your website publication in the AddBinaryAddBinary
method. You may not, though, change the path of an existing SG. It's not a property you can set. AnAn image must be associated with an existing structure group. HoweverHowever, you choose what SG you publish a binary to in your TBBs. SoSo what you can do is call the AddBinaryAddBinary
method with any SG that you have.
If you want to specify an SG that has the same path as the Folder that the image is in, then you can add logic to check if such as SG exists, and if not, create the SG based on the Folder path.
Here is a sample method that checks for an existing SG based on the a given Folder:
protected StructureGroup GetStructureGroupBasedOnFolder(Folder folder)
{
Logger.Debug("Entering method GetStructureGroupBasedOnFolder");
string folderWebDavUrl = folder.WebDavUrl;
//Get the folder's relative path excluding "Building%20Blocks/Content"
int indexOfRootFolder = folderWebDavUrl.IndexOf("Building%20Blocks/Content");
string firstPath = folderWebDavUrl.Substring(0, indexOfRootFolder);
string relativeFolderPath = folderWebDavUrl.Replace(firstPath + "Building%20Blocks/Content", string.Empty);
string.Empty);
Logger.Debug("relative folder path=" + relativeFolderPath);
Publication pub = folder.ContextRepository as Publication;
string pubSGWebDavUrl = pub.RootStructureGroup.WebDavUrl;
string publishSGWebDavUrl = pubSGWebDavUrl + relativeFolderPath;
Logger.Debug("publish SG webdav url=" + publishSGWebDavUrl);
StructureGroup sg = m_Engine.GetObject(publishSGWebDavUrl) as StructureGroup;
Logger.Debug("Returning from method GetStructureGroupBasedOnFolder");
return sg;
}
You may also be creative on the CD side. For example, implement a custom storage extension that puts your images in a CDN and specifies their path. Will has written a nice high-levellevellevel article about CDN publishing here: http://www.tridiondeveloper.com/some-thoughts-on-cmscdn-integration