This is dependent on what event you are trying to get this information from. Are you listening on the Opening Event as you mention, Save Event, or are you trying to gather this from an ExternalCommand?
Below is a sample from an event:
/// <summary>
/// Called when [document closing].
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="args">The <see cref="DocumentClosingEventArgs" /> instance containing the event data.</param>
/// ReSharper disable once MemberCanBeMadeStatic.Local
private void OnDocumentClosing(object sender, DocumentClosingEventArgs args)
{
try
{
if (Path.GetExtension(args.Document.PathName).Equals(".rvt", StringComparison.CurrentCultureIgnoreCase)
&& !args.Document.IsFamilyDocument && args.Document.PathName != string.Empty)
{
......
}
}
}
It does not have to be done like this, but this is a sample.
From an ExternalCommand:
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class LaunchSomething : IExternalCommand
{
/// <summary>
/// Executes the specified Revit command <see cref="ExternalCommand"/>.
/// The main Execute method (inherited from IExternalCommand) must be public.
/// </summary>
/// <param name="commandData">The command data / context.</param>
/// <param name="message">The message.</param>
/// <param name="elements">The elements.</param>
/// <returns>The result of command execution.</returns>
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
Document doc = commandData.Application.ActiveUIDocument.Document);
return Result.Succeded;
}
catch (Exception ex)
{
return Result.Failed;
}
}
}