From the Autodesk Forge website:
Check the version of a Revit file hosted on the cloud
By
Augusto Goncalves
February 21, 2019
With Design Automation for Revit we can select which engine to use, 2018 or 2019. And it's important to choose the correct one in order to avoid opening with an older version or saving with a newer version, e.g. if you have a 2018 file and open and save with 2019 engine.
Jeremy Tammik did an interesting
blog post about it, in summary reading the file information that is encoded inside the bytes. This approach still valid, but if the file is on the cloud, we don't want to download it (it may be too big). But we don't need, actually, just need the first few KBs.
The following code sample downloads a few KBs, then if it finds "Autodesk", it created a dictionary with the values.
private async Task<Dictionary<string, string>> GetInfo(string storageLocation, string accessToken)
{
if (storageLocation.IndexOf(".rvt") == -1) return null;
WebClient webClient = new System.Net.WebClient();
webClient.Headers.Add("Authorization", "Bearer " + accessToken);
System.IO.Stream stream = webClient.OpenRead(storageLocation);
byte[] buffer = new byte[ 10 * 1024];
int res = 0;
int count = 0;
do
{
if (count++ > 10) return null;
res = await stream.ReadAsync(buffer, 0, 10 * 1024);
string rawString = System.Text.Encoding.BigEndianUnicode.GetString(buffer);
if (!rawString.Contains("Autodesk")) continue;
var fileInfoData = rawString.Split(new string[] { "\0", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
Dictionary<string, string> values = new Dictionary<string, string>();
foreach (var info in fileInfoData)
if (info.Contains(":"))
values.Add(info.Split(":")[0], info.Split(":")[1]);
return values;
} while (res != 0);
return null;
}