Short solution for short problems

Show WSS docs in ASP.Net site

If you are using a WSS based site on the inside of your company, sometimes you want to share some documents to the outside without sharing the complete library or without giving them acces to your SharePoint site. Then you will need to acces the WSS site with a user and render the document on your ASP.Net page.

This is how I solved it a while ago.

I created a list of documents grom the WSS library on the site using the webservices. Each listitem(ASP.Net list item) provided a link, which had a query string: docurl, that provided the url in the SharePoint document. (If the url is not to be shown, you could use doc ID instead).

Then when you clicked on the link, the url was transmitted via querystring and these functions handled the rendering:

        private byte[] ReadFully(Stream stream)
            byte[] buffer = new byte[32768];
            using (MemoryStream ms = new MemoryStream())
                while (true)
                    int read = stream.Read(buffer, 0, buffer.Length);
                    if (read <= 0)
                        return ms.ToArray();
                    ms.Write(buffer, 0, read);
        private void ShowDocToUser(string s)
            WebClient wc = new WebClient();
            wc.Credentials = GetCredentials();
            Stream data = wc.OpenRead(s);
            byte[] content = ReadFully(data);
            WebHeaderCollection webHeaders = wc.ResponseHeaders;
            Response.ContentType = webHeaders["Content-Type"];

The getcredentials function uses login and password of a user that is configured in the webconfig and has read acces to the library.