Download a Sharepoint File with GraphServiceClient (Microsoft Graph API)

By Robert Ellison. Updated on Tuesday, November 19, 2024.

Demons protect a PowerPoint presentation from developers trying to access it.

There is a stunningly simple way to get a file out of sharepoint and I'll get to that soon (or just skip to the very end of the post).

I have been automating the shit out of a lot of routine work in Microsoft Teams recently. Teams is the result of Skype and Sharepoint having too much to drink at the Microsoft holiday party. It often shows. One annoyance is that channel threads are ordered by the time that someone last responded. Useful for quickly seeing the latest gossip but a pain when you need to keep an eye on each individual thread. After listlessly scrolling around trying to keep up with the flow I came up with a dumb solution - I sync the channel to Obsidian (my choice of note app, could be anything) and then I can just check there for new threads. It's a small convenience but has meaningully improved my life.

Unfortunately I got greedy. These messages usually have a PowerPoint presentation attached to them and so why not have an LLM summarize this while updating my notes?

It doesn't look like Copilot has a useful API yet. You can build plug-ins, but I don't want to talk to Copilot about presentations, I just want it to do the heavy lifting while I sleep so I can read the summary in the morning. Hopefully in the future there will be a simple way to say hey, Copilot, summarize this PPTX. Not yet.

So the outline of a solution here is download the presentation, send it ChatGPT, generate a summary and stick that in Obsidian. This felt like a half hour type of project. And it should have been - getting GPT4 Turbo to summarize a PPTX file took about ten minutes. Downloading the file has taken days and sent my self esteem back to primary school.

You would think that downloading a file would be the Graph API's bread and butter. Especially as I have a ChatMessage from the channel that includes attachments and links. The link is for a logged in human, but it must be easy to translate from this to an API call, right?

It turns out that all you need is the site ID, the drive ID and the item ID.

These IDs are not in the attachment URL or the ChatMessageAttachment. It would be pretty RESTful to include the obvious next resource I'm going to need in that return type. No dice though.

I tried ChatGPT which helpfully suggested API calls that looked really plausible and helpful but that did not in fact exist. So I then read probably hundreds of blogs and forum posts from equally confused and desperate developers. Here is a typical example:

"Now how can I upload and download files to this library with the help of Graph API (GraphServiceClient)."

To which Microsoft, terrifyingly, reply:

"We are currently looking into this issue and will give you an update as soon as possible."

Before eventually suggesting:

"await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Content.GetAsync();"

Ignoring the sharepoint part and glossing over where that drive ID is coming from. Other documentation suggests that you can lookup your site by the URL, and then download a list of drives to go looking for the right one. Well, the first page in paginated drive collection anyway implying that just finding the ID might get you a call from the quota police.

I know Microsoft is looking after a lot of files for a lot of organizations, but how can it be this hard?

It isn't. It's just hidden. I eventually found this post from Alex Terentiev that points out that you just need to base64 encode the sharing url, swap some characters around and then call:

"GET https://graph.microsoft.com/v1.0/shares/{sharing-url}/driveItem"

If Google was doing its job right this would be the top result. I should be grateful they're still serving results at all and not just telling me that my pastimes are all harmful.

The documentation is here and Microsoft should link to it on every page that discusses drives and DriveItems. For GraphServiceClient the call to get to an actual stream is:

"graphClient.Shares[encodedUrl].DriveItem.Content.GetAsync()"

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Download a Sharepoint File with GraphServiceClient (Microsoft Graph API) #code #ml #graph #sharepoint #c# Everyone developing applications with the Graph API should know about the shares endpoint that allows you to download files easily. )

Links for March 2024

By Robert Ellison. Updated on Sunday, March 31, 2024.
InfoWorld: White House urges developers to dump C and C++

Developers urge White House to dump Electoral College and supermajority cloture. #politics #electoralcollege #cloture #c #c++

--

The New Yorker: What Have Fourteen Years of Conservative Rule Done to Britain?

"In messages during the pandemic, he referred to ministers as “useless fuckpigs,” “morons,” and “cunts.” The inquiry’s lawyer asked Cummings if he thought his language had been too strong. “I would say, if anything, it understated the position,” he replied." This is a depressing but definitive read as we wait for the UK election to be announced. #politics #uk

Add your comment...

Related Posts

(All Etc Posts)

FRA BLR

FRA BLR

Google Pixel 8 Pro 7mm f1.7 1/100s ISO21

LH754

Add your comment...

Related Posts

(Recent Photos)

(Published to the Fediverse as: FRA BLR #photo #plane #fra #blr FRA BLR )

SFO FRA

SFO FRA

Google Pixel 8 Pro 7mm f1.7 1/3,800s ISO21

LH455

Updated 2024-03-01 04:28:

SFO FRA

Northern Lights

Add your comment...

Related Posts

(Recent Photos)

(Published to the Fediverse as: SFO FRA #photo #plane #sfo #fra SFO FRA )

TDCommons and the Future of Patent Law

An illustration of a patent figure for some Hello World generation

Paresh Dave in Wired writes about TDCommons.org, a Google funded but bepress operated site. The idea is to publish technical disclosures as prior art that might invalidate future patents. It's an interesting overview of the subject, including a USPTO attempt to do the same thing (I covered this here) and a commercial competitor, IP.Com. Apparently USPTO is looking for help with this problem:

"Google is hoping TDCommons has a chance to be embraced as Kathi Vidal, a tech patent attorney who was sworn in as director of the USPTO almost two years ago, settles into her role. Deciding that generative AI programs can’t be patent holders has been a higher priority, she says, but creating a better search tool for prior art is an issue she’s discussed with a lot of organizations. Vidal says she’s open to the USPTO administering and funding its own prior art repository, offering up her email, [email protected], for feedback on how to do so."

I'm not super-convinced that she's providing her actual email address, but when I have a few minutes I might suggest my own plan - issue all patent applications and shift the examination to the start of any litigation or enforcement attempt.

Add your comment...

Related Posts

(All Politics Posts)

(Published to the Fediverse as: TDCommons and the Future of Patent Law #politics #patents #uspto Prior art attempts like TDCommons, IP.com and even the USPTO's failed scheme should be replaced with a fundamental overhaul of the patent system. )

Links for February 2024

By Robert Ellison. Updated on Saturday, February 24, 2024.

Tide Line from Lands End

Tide Line from Lands End

Google Pixel 8 Pro 7mm f1.7 1/1,000s ISO21

View of a very distinct tide line from Lands End in San Francisco.

Add your comment...

Related Posts

(Recent Photos)

(Published to the Fediverse as: Tide Line from Lands End #photo #tideline #sanfrancisco #landsend Photo from Lands End in San Francisco showing a distinct tide line. )

Sunrise, Ulloa and 15th

By Robert Ellison. Updated on Monday, February 19, 2024.

Sunrise, Ulloa and 15th

Google Pixel 8 Pro 7mm f1.7 1/45s ISO18

Dramatic sunrise at Ulloa and 15th Avenue in San Francisco.

Add your comment...

Related Posts

(Recent Photos)

(Published to the Fediverse as: Sunrise, Ulloa and 15th #photo #sunrise #sanfrancisco Photo of sunrise in San Francisco at Ulloa and 15th Avenue. )

Reviews for February 2024

By Robert Ellison. Updated on Thursday, February 15, 2024.

Spoilers!

TV

A Spy Among Friends

A Spy Among Friends

Not since the Kenneth Branagh version of Wallander has a TV series put me so comprehensively to sleep. I love Scandi Noir, I love Kenneth Branagh and yet through four seasons I didn't finish a single episode. A Spy Among Friends is an espionage 'thriller' with a fantastic cast set around the penetration and defection scandal of Kim Philby. It should be a compelling story but I can't say for sure because it was like a  rohypnol in a double Long Island Iced Tea. YMMV.

Bodies

Bodies

Bodies starts with the same dead person in several different periods and pretty soon four detectives are investigating four strangely similar cases. It's the most BBC thing I've watched in years, I really enjoyed it.

Reacher Season 2

Reacher Season 2

Season 2 takes on Bad Luck and Trouble. I wonder what they're going to do when they run out of books where Reacher has collaborators. His inner monologue is pretty hard to translate to TV. The first season went for a comedy sidekick cop to add in the humor and it worked pretty well. Season 2 is a lot darker and a lot less Reacher as a result. Hopefully they tack back and find a better tone for Season 3.

The Crown Season 6

The Crown Season 6

The Crown putters to a quiet end. It was quite compelling to start with and got less so the closer it gets to the modern era. I think probably because it starts to overlap with events I remember quite vividly, and can't really compete with those memories. In the last episode we jump back to WWII era Elizabeth and I wish they'd done a whole series just on that. Maybe that will be a spinoff. While an interesting historical drama, the fantasy ending I'm looking for is more like this.

(All images included with ITHCWY reviews are the property of their respective owners and are used to illustrate reviews only.)

Add your comment...

Related Posts

(All Reviews)

San Francisco and California March 2024 Ballot Measures

Kids learning Algebra

While waiting for the horror of Weekend at Bernie's vs. A Clockwork Orange in November there is time to contemplate another slate of job-outsourcing ballot measures. Just one for California and seven for San Francisco so it could be worse. Here goes...

California Proposition 1, Behavioral Health Services Program and Bond Measure

Yes. This funds housing and treatment for the mentally ill, homeless and veterans in need. It also requires counties to put more of their existing funds into housing.

San Francisco, California, Proposition A, Affordable Housing Bond Measure

Yes. $300M in bonds to build, buy and repair affordable housing. Homelessness is driven by a lack of affordable housing. In addition to building more I'd love to see us cut more of the red tape, but this is a necessary measure to meet our existing obligations.

San Francisco, California, Proposition B, Minimum Police Staffing Amendment

No. I voted against minimum numbers in 2020, and I don't see a good reason to bring them back today. I also recoil at the thought of a dedicated police recruitment tax as this measure suggests. Funding the police is a very basic city service, as is determining the appropriate staffing levels at any particular moment in time. I'm not against recruiting more police at all, but this is a bad proposal.

San Francisco, California, Proposition C, Real Estate Transfer Tax Exemption for Properties Converted from Commercial to Residential Use Initiative

Yes. I voted in favor of this tax in 2020. Post pandemic San Francisco has one of the worst return to office rates and a huge decline in retail. We need to rethink what downtown is for and I love the idea of bringing in more universities and more homes. So this is a tax break that makes sense for now.

San Francisco, California, Proposition D, Amend City Ethics Laws and Expand Restrictions on Gifts to City Officers and Employees Initiative

Yes. Tougher ethics rules are needed. Can't find any reason to oppose this package. We have bribing of inspection personnel, theft of public funds, corruption in Public Works, that inspector who inspected his own building, etc.

San Francisco, California, Proposition E, Limit Police Department Administrative Task Time and Increase Use of Camera and Drone Technology Initiative

Yes. Apparently when SFPD decides to chase someone they crash 38% of the time, about twice the state average. This bill would let them chase more people and use drones and GPS taggers to do it. I'd like them to go on an advanced driving course or two, but if you can avoid consequences just by running away then we don't really have a law enforcement system. Maybe I'll regret this in a few years but it seems mostly common sense to me right now.

San Francisco, California, Proposition F, Require Drug Screening for Certain Beneficiaries of the County Adult Assistance Program Initiative

No. It looks like the recipients of most of these funds are not homeless and have plenty of hoops to jump through already. This seems like it would risk making their situation worse.

San Francisco, California, Proposition G, Declaration of Policy Urging San Francisco Unified School District to Offer Algebra 1 to Students by Eighth Grade Measure

Yes. This is pointless as it has no teeth and they're moving this way anyway. I still want to help make the pointless point.

Add your comment...

Related Posts

(All Politics Posts)

(Published to the Fediverse as: San Francisco and California March 2024 Ballot Measures #politics #sanfrancisco #propositions #election #california ITHCWY voter guide to the San Francisco and California March 2024 primary election propositions and ballot measures. )