Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Bypassing WSS Document Library Security to retrieve documents

I needed to provide access to items from selected folders in a SharePoint Services 2.0 Document Library. I couldn't give read access to the entire library (your only option in WSS 2.0) because allowing them to browse the entire folder tree was not an option.

So I wrestled with options of opening the docs from an anonymous web page passing a valid WSS user's credentials, investigated the SPS DWS web service (which I used in the past for creating document folder trees), and wasted an hour or so with the Microsoft.Sharepoint libraries, considering a strategy where I could duplicate folder contents to another document library or something.  (Does anyone do anything useful with those libraries outside of building webparts in .NET 1.1?  Does anyone else find the API difficult to understand?)

So I decided to screw the whole WSS approach to retrieving documents and went straight to SQL.  What I did, essentially, was to retrieve the binary directly from the WSS SQL database using the item's GUID.  Works like a charm, document library is secure, and the documents open in their native applications: Excel, Work, TextPad, Acrobat, etc. 


private void Page_Load(object sender, System.EventArgs e)
{
 if (!IsPostBack)
 {
  string guid = Request.QueryString["guid"].ToString();
  SqlDataReader dr = DataSharepointHelper.GetDocDescByGuid(guid);
  dr.Read();
  Response.OutputStream.Write((Byte[]) dr["Content"],0, int.Parse(dr["Size"].ToString()));
  Response.AddHeader("Content-Disposition", "attachment;filename=" + dr["leafname"].ToString());
 }
}

 

Comments (3) | Post RSS RSS comment feed

Posted on 10/28/2004 7:24:00 AM by Dave Burke
Categories: .NET
Tags:

Related posts

Comments (3) -

10/29/2004 10:02:00 AM Permalink

Testing the CAPTCHA component

Dave Burke |

7/20/2005 12:11:44 AM Permalink

Could u pls elaborate on how to retrieve documents using it's GUID

venkat |

7/20/2005 6:15:57 AM Permalink

Venkat,

I'm querying a view I created in the SharePoint SQL database to pull the document information (including the binary doc) based on its GUID.  The tables comprising the view are Docs and UserData.

Hope that helps.
D.

daveburke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke