get current user from word add-in sharepoint
-
29-09-2020 - |
Pergunta
How can i get the current user that loaded a file from a sharepoint library?
When I load a file from a doc library on sharepoint, Word prompts me a window to type my UserName and Password to connect to the sharepoint site.
How can I get this username on the add-in or on the server side?
I've beem trying to use on the server side using:
SPUser user = SPContext.Current.Web.CurrentUser;
I tought that was going to solve my problems, but it seems to get always the same user, it doesn't matter which one I log-in on the MSWord prompt or on the Sharepoint Site for some reason.
Does anyone know what might be the solution?
Solução
I don't think you will be able to get the username and password (or the token) that the user has provided to Word or any office application.
This will be a risk if such a way exist in the first place.
For the current user (the user who logged into the system) you can invoke the webservice and pass the network credentials as
Uri uri = new Uri("http://tempuri.org/");
ICredentials credentials = CredentialCache.DefaultCredentials;
NetworkCredential credential = credentials.GetCredential(uri, "Basic");
Another option is to create your own form and request the user for credentials so You can cache it somewhere and use it for communication with SharePoint