Using DataPackage.ResourceMap doesn't work.
-
quarta-feira, 9 de maio de 2012 03:30
This article demonstrates how to provide associated content with HTML: http://msdn.microsoft.com/en-us/library/hh758310.aspx. Unfortunately there is no C# example, so I have converted it c#:
var request = args.Request; var htmlExample = "<p>Here is our store logo: <img src='images/logo.png'>.</p>"; var fileExample = "images\\logo.png"; var file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\logo.png"); RandomAccessStreamReference streamRef = null; try { streamRef= RandomAccessStreamReference.CreateFromFile(file); } catch (Exception ex) { //document.getElementById("output").innerText = "Fail."; } var htmlFormat = HtmlFormatHelper.CreateHtmlFormat(htmlExample); request.Data.Properties.Title = "Share Html Example"; request.Data.Properties.Description = "A demonstration that shows how to share."; request.Data.ResourceMap[fileExample] = streamRef; request.Data.SetHtmlFormat(htmlFormat); request.Data.ResourceMap[fileExample] = streamRef;And it correctly loads the file and puts it into the resource map. But when I select the mail share target, all that appears is a cross with the image should be.
Is there a problem with my conversion to C#, or an underlying issue?
...Stefan
- Editado StefanOlson quarta-feira, 9 de maio de 2012 21:12 fixing code bug
Todas as Respostas
-
quarta-feira, 9 de maio de 2012 21:05Moderador
One problem in your conversion and one in your expectations:
First, it doesn't look like you actually set the resource map in your code. You need to take your streamRef and add it into the request's Data:
request.Data.ResourceMap["images\\logo.png"] = streamRef;
Second, you need to share with a target that understands the resource map, which the Mail program doesn't do. If you modify the share target app to examine the resource map it receives you'll see that the logo.png does get delivered.
The resource map passes the stream along in a dictionary so the share target can extract it and store the referenced resource somewhere the HTML can find it. If the share target can do something useful with that then it can extract the file and make use of it, but the Mail program does not do so.
--Rob
- Marcado como Resposta StefanOlson quarta-feira, 9 de maio de 2012 21:12
-
quarta-feira, 9 de maio de 2012 21:11
Rob,
Good point, not entirely sure how I missed that line, as I did have that line in my own code that I had in place before I rewrote it to make it smaller and simpler. will correct my code sample for others it may find it useful.
I had assumed that if there was any share target that would examine the resource map, it would be the Mail program. Basically makes using the resource map at this stage waste of time, because if someone tries to share a with a mail target, then they are not going to see any images, so for the moment I'll just use Web images, and hope that is resolved by RTM.
I guess it's a bit unfortunate that there is no way of telling when you share the data whether or not the resource map is going to be used, so you can't use Web images in one situation and local images and other.
...Stefan
-
quarta-feira, 1 de agosto de 2012 21:53Any idea if something has changed? I want to compose an email with an image and I thought the HTML route might work, but if the Mail app does not accept these images - I can't see what to do...
Filip Skakun

