VMware {code} Community
jrwise
Enthusiast
Enthusiast

List And Delete Media Within vDC

I am looking for a way to list media within a vDC to determine if it needs to be deleted before the vDC is removed. Also, I would like to delete any files found.

Can anyone help me?

Reply
0 Kudos
1 Reply
jrwise
Enthusiast
Enthusiast

I have made progress. I figured out a method to delete media found in a vDC. It works, however I am getting an "Access is forbidden" message as the method loops through each media file. The file actually gets deleted, but exits out of the method because of the thrown error. Any help is appreciated. Code is below:

        internal static void FindMediaInvDC(string vDCName)

        {

            try

            {

                Vdc vdc = FindVdc("MyOrg", vDCName);

                List<ReferenceType> media = vdc.GetMediaRefs();

               

                foreach (ResourceReferenceType mediaFile in media)

                {

                    Console.WriteLine("Name: " + mediaFile.name + " - " + "HREF " + mediaFile.href);                  

                    Media.DeleteMedia(objConn.client, mediaFile);

                }

            }

            catch (Exception ex)

            {

                throw new VCloudException(ex.Message);

            }

        }

Reply
0 Kudos