Quantcast
Channel: Open XML Format SDK forum
Viewing all articles
Browse latest Browse all 1288

Still having troubles getting unused relationship IDs

$
0
0

Hi all,


I already posted a while ago with basically the same problem. I am trying to add a shape with a hyperlink to an existing presentation. Therefore I have to give the shape a static relationship ID (rID) since Office will otherwise complain that the shape is corrupted and will therefor remove it before opening the presentation.

To redeem this problem I loop through all the existing IDs on the slides, get the highest of them and add to it:


List<int> IDList = new List<int>(); foreach (Shape ShapeID in slide.Slide.Descendants<Shape>()) {

IDList.Add(int.Parse(ShapeID.NonVisualShapeProperties.NonVisualDrawingProperties.Id)); } return IDList.Max() + 1;

Apperently, these ID do not include the Hyperlink IDs which are given to Hyperlinks. The only way I found to get these rIDs is to store them as strings, convert them to integers and then get the highest of those (seems kind of complicated in hindsight, but there you are):


List<string> ret = new List<string>();
List<int> ids = new List<int>();
IEnumerable<Drwng.HyperlinkType> links = slide.Slide.Descendants<Drwng.HyperlinkType>();
// Iterate through all the links in the slide part.
foreach (Drwng.HyperlinkType link in links)
{
	// Iterate through all the external relationships in the slide part.
	foreach (HyperlinkRelationship relation in slide.HyperlinkRelationships)
	{
		ret.Add(relation.Id);
	}
		}
for (int i = 0; i < ret.Count; i++)
{
	ret[i] = Regex.Replace(ret[ret.Count - 1], "^[a-zA-Z]*", "");
	ids.Add(int.Parse(ret[i]));
}
if (ids.Count() > 0)
{
	maxID = ids.Max();
}
else
{
	maxID = 0;
}

Then I added these two numbers up, reasoning that the resulting number has to be the highest existing number. For the case, that there were no Hyperlinks on the slide I added 1 again. Just to be safe. This construct worked fine for a while. But today it threw me an exception because the ID already existed:

Does anyone know what I am doing wrong or an alternative way to check for used rIDs?

Cheers



Viewing all articles
Browse latest Browse all 1288

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>