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();
So at the moment I've been playing around with the new Microsoft Live controls that have been released into the developers world. The problem is that it's so new that hardly anyone has done anything with them, and if they have they haven't done anything worthwhile.I've been having a go at adding these controls as a webpart.
To get started you need to install:
1. The live controls.
To download these controls, go to the Windows Live Tools Web site, http://dev.live.com/tool Instructions on installing the controls as well as a list of any prerequisites for the controls are listed on this site. 2.You also require SharePoint extensions in Visual Studio.
1. Create a new webpart: 1. File > New > Project 2. Select SharePoint > Web Part 3. Name: MSNChatWebPart 4. Location: Your development folder e.g. D:\DEV\ 5. SolutionName: MSNChatWebPart 6. Make sure your screen looks like the following :
Then hit OK.
You should now have a new Web Part project.
2. Add a Reference
Find the Microsoft.Live.ServerControls.dll
copy this DLL into the D:\Dev\MSNChatWebPart\ MSNChatWebPart\bin folder and also into the GAK folder of the SharePoint project.
Add a reference to the above DLL in your project. Use the DLL in your bin folder.
In your WebPart1.cs file add the following using statement above the namespace
using Microsoft.Live.ServerControls;
3. Adding the Control
1. You will need to programmatically add the control to the Web Part. 2. This control can be configured to your liking. For now we are going to only some basic configuration.A full list of options is available a http:/msdn.microsoft.com/en-us/library/cc305083.aspx
I will talk more about this in a future post
3. Just note that the PrivacyStatementURL is required in order for this control to work.For now you can create a default page named PrivacyPolicy.aspx You need to add thefollowing code to your project
//add this control to the controls collention of the webpartthis.Controls.Add(myessengerChat);
}
This will add the MSNChat control .
4. Build your solution 5. Make sure in your Project Properties under Debug the Start browser with URL is set to your SharePoint site path 6. Deploy the solution
4. Add the web part to your site
1. Go to the design view of your page. 2. Click Add a Web Part on any zone. In this example we will add in to the middle zone 3. Expand All WebParts > and select your WebPart1 Web Part>>Add
So there we have it a nice simple MSNChat webpart for your mySite.
So this is something new for me. I've just discovered that blogging is the new thing to do so I decided to join the fad and start my very own blog. Pretty much this blog will end up containing a lot of mush about .NET Development in C#
Yes I am aware that there are many other blogs out there that do the same thing but this one will be all mine so there. That's all the justification that I need. I think from my perspective is that this will be useful for other developers out there who are looking for solutions to issues that I may have faced and solved, something interesting I learned or just anything that I feel like ranting on about.
So far so good. I'm recently back from the Microsoft TechEd conference that was held in Auckland NZ so once my brain is back in action I will be posting some things about my learnings.