I came across this issue the other day. I was trying to copy an image from a site into my SharePoint list. The issue was that the Stream that I was receiving was not seekable making it impossible to find out its size. After some awesome google skills and some help from my workmate we came up with a simple solution.
We copy the unseekable stream 64bytes at a time into a new stream making it seekable.
and TADA, this is what you end up with
private static void CopyUnseekableStream(Stream input, Stream output) { if (input == null) throw newArgumentNullException("input"); if (output == null) throw newArgumentNullException("output");
try { using (BinaryWriter bwWriter = new BinaryWriter(output)) using (BinaryReader brReader = new BinaryReader(input)) { byte[] buf; do { buf = brReader.ReadBytes(1024 * 64); // you can make this any size bwWriter.Write(buf); } while (buf.Length > 0); bwWriter.Close(); brReader.Close(); } } catch (Exception ex) {
We all know that Microsoft have released new live BETA controls for the development community to use. I've been playing around with the Virtual Earth control and trying to get it to work within a Share Point web part.
I started this development using just a plain HTML page to see how the functionality works. I've had a go at adding the control to the page and add/remove/move/load pins. Pins will be the most important part of your virtual earth. Whether you want to or not, users want to have the ability to plot destinations on the globe. There are many different reasons why a user would want to plot locations. To be honest I don't care why, as to HOW now that's what I want to discover.
We need to start this easy html page by referencing the control and adding the control to the page, and adding the required radio buttons that we will use to determine our users action. This is due to the fact that there is no Right click in web!
I start with a basic html page so that you can work out all the necessities for your JavaScript code. Since you can't really debug the js from your web part you will need to debug it in VS 2008 !
Let's begin.
1. We need to add all the required elements to the page. We need to reference the js control and from Microsoft.
<input type="hidden" id="VEpin_msftve_1000_200002" value="This is pin 2;-41.28519169519274;174.77449893951424" />
<input type="hidden" id="VEpin_msftve_1000_200003" value="this is pin 3;-41.28699756258909;174.77278232574466" />
This hidden input contains some crucial information. The pin description (this will appear in the info box and also the Longitude and Latitude.) Since there is no right click in web we need to add some radio buttons. This will help determine what action the user wants to perform. So we add a radio group.
<input id="addPin" name="pinOptions" type="radio" value ="AddPin">Add Pin</input> <input id="removePin" name="pinOptions" type="radio" value ="RemovePin">Remove Pin</input> <input id="navigate" name="pinOptions" type="radio" value ="navigate" checked ="checked" >Navigate</input> Navigate</input>
Add Pin Remove Pin Navigate
It is pretty self explanatory.
3. Let's add first functionGetMap();
function GetMap() {
map = new VEMap('myMap'); map.LoadMap();
var LL = new VELatLong(); LL.Longitude = '174.77620487244477'; LL.Latitude ='-41.28656222412803';
var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter()); shape.SetDescription('Provoke Solutions'); shape.SetMoreInfoURL('http://www.provoke.co.nz/'); shape.SetCustomIcon('http://localhost:1221/Desktop/provoke.jpg'); shape.SetLineColor(new VEColor(0,150,100,1.0)); shape.SetFillColor(new VEColor(0,100,150,0.5)); shape.ShowIcon(); map.AddShape(shape);
}
4. Load Pins
We now need to load
function loadPins() { var hiddenPins = document.getElementsByTagName("input");
for( i = 0; i < hiddenPins.length; i ++) { if (hiddenPins[i].getAttribute('type') == 'hidden') { var inputID = hiddenPins[i].getAttribute('id').substr(0,5);
if (inputID == 'VEpin') { var oldPin = hiddenPins[i].getAttribute('id').replace('VEpin_',''); var pinDetails = hiddenPins[i].value;
var arrPinDetails = pinDetails.split(";"); var LL = new VELatLong(); LL.Longitude = arrPinDetails[2]; LL.Latitude = arrPinDetails[1];
var newPin = new VEShape(VEShapeType.Pushpin,new VELatLong(LL.Latitude, LL.Longitude)); map.AddShape(newPin); pinId = newPin.GetID();