Friday, July 20, 2012

Remove User from User Information Table

Remove a single user from User Information table:
Remove a user based on Login Name
web.AllowUnsafeUpdates = true;
string userName = "domainname\\username";
SPUser user = web.SiteUsers[userName];
 if (!user.IsDomainGroup && !user.IsSiteAdmin)
web.AllowUnsafeUpdates = false;

Remove Multiple user:
Remove multiple user based on Domain name
web.AllowUnsafeUpdates = true;
SPList _list = web.Lists.TryGetList("User Information List");
SPQuery qry = new SPQuery();
qry.Query = "<Where><Contains><FieldRef Name='Name' /><Value Type='Text'>Domainname</Value></Contains></Where>";
SPListItemCollection _itmcol = _list.GetItems(qry);
if (_itmcol.Count > 0)
      string userName = "";
     foreach (SPListItem itm in _itmcol)
        userName = Convert.ToString(itm["Name"]);
        SPUser user = web.SiteUsers[userName];
        Console.WriteLine(userName + "("+ Convert.ToString(itm["Title"])+ ")" + "\n");
web.AllowUnsafeUpdates = false;

Can't access/open Central Administration

System.ArgumentNullException: No message was deserialized prior to calling the DispatchChannelSink.
Parameter name: requestMsg  
at System.Runtime.Remoting.Channels.DispatchChannelSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders & responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.SoapServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)  
at System.Runtime.Remoting.Channels.Http.HttpServerTransportSink.ServiceRequest(Object state)  
at System.Runtime.Remoting.Channels.SocketHandler.ProcessRequestNow().

May be your SharePoint Central Administration port is used by another process.
  1. Open Command Prompt(with Run as Administrator).
  2. Run this command netstat -na -nao.
  3. Now you can see your Active connections.
  4. Find you Central admin port ID.
  5. Here Central Admin Port ID is 8093 PID is 4088.
  6. Go to Task Manager > Services> find your PID (like 4088).
  7. Right click on that select Go to Process.
  8. Kill/Close the selected Process. (Note: if no one process is selected check the show process from all user check box below).
  9. Reset IIS.
  10. Now try to access you Central Administration :)

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...