Skip to main content
Undented the code to fit better, removed intro (should be a comment) and marked some inline code fragments
Source Link

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

Welcome to the Tridion community Vinoth!

You may specify any existing SG in your website publication in the AddBinary method. You may not, though, change the path of an existing SG. It's not a property you can set. An image must be associated with an existing structure group. However, you choose what SG you publish a binary to in your TBBs. So what you can do is call the AddBinary 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);
        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-levellevel article about CDN publishing here: http://www.tridiondeveloper.com/some-thoughts-on-cmscdn-integration

You may specify any existing SG in your website publication in the AddBinary method. You may not, though, change the path of an existing SG. It's not a property you can set. An image must be associated with an existing structure group. However, you choose what SG you publish a binary to in your TBBs. So what you can do is call the AddBinary 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);
  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-level article about CDN publishing here: http://www.tridiondeveloper.com/some-thoughts-on-cmscdn-integration

added 62 characters in body
Source Link
Nickoli Roussakov
  • 18.4k
  • 4
  • 31
  • 62

Welcome to the Tridion community VinodthVinoth!

Yes, youYou may specify any existing SG in your website publication in the AddBinary method. You may not, though, change the path of an existing SG. It'sIt's not a property you can set. An An image must be associated with an existing structure group. However, you choose what SG you publish a binary to in your TBBs. So what you can do is call the AddBinary 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);
        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-levellevel article about CDN publishing here: http://www.tridiondeveloper.com/some-thoughts-on-cmscdn-integration

Welcome to the Tridion community Vinodth!

Yes, you may specify any existing SG in your website publication in the AddBinary method. You may not, though, change the path of an existing SG. It's not a property you can set. An image must be associated with an existing structure group. So what you can do is call the AddBinary 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);
        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-levellevel article about CDN publishing here: http://www.tridiondeveloper.com/some-thoughts-on-cmscdn-integration

Welcome to the Tridion community Vinoth!

You may specify any existing SG in your website publication in the AddBinary method. You may not, though, change the path of an existing SG. It's not a property you can set. An image must be associated with an existing structure group. However, you choose what SG you publish a binary to in your TBBs. So what you can do is call the AddBinary 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);
        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-levellevel article about CDN publishing here: http://www.tridiondeveloper.com/some-thoughts-on-cmscdn-integration

Source Link
Nickoli Roussakov
  • 18.4k
  • 4
  • 31
  • 62

Welcome to the Tridion community Vinodth!

Yes, you may specify any existing SG in your website publication in the AddBinary method. You may not, though, change the path of an existing SG. It's not a property you can set. An image must be associated with an existing structure group. So what you can do is call the AddBinary 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);
        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-levellevel article about CDN publishing here: http://www.tridiondeveloper.com/some-thoughts-on-cmscdn-integration