Calling OpenBinaryStream throws COM exception - 0x80070092

 

Create an instance of SPFile using GetFile method and pass the GUID of the file in its parameter. Then immediately call OpenBinaryStream method in the instance of spfile. It then throws a COM exception "The path specified is being used in a substitute. (Exception from HRESULT: 0x80070092)"

 

SPFile oSPFile = OSPWeb.GetFile("GUID of the file");

Stream oStream = oSPFile.OpenBinaryStream();

 

But, at the same time, the below mentioned code works fine.

 

SPFile oSPFile = OSPWeb.GetFile("GUID of the file");

string strName = OSPFile.Name;

Stream oStream = oSPFile.OpenBinaryStream();

 

Or even, this code works.

 

SPFile oSPFile = OSPWeb.GetFile("URL");

Stream oStream = oSPFile.OpenBinaryStream();

 

There is a method in the SPFile class called GetFileStream. This method calls the COM level method GetFileAsStream which accepts webRelativeUrl as one of the parameters. When we access a property of the file before calling the OpenStream method this method gets populated with the relative path of the file we are working with. If we directly call the method OpenBinaryStream right after we get the file though the GUID, this parameter is null and will fail with the exception:"The path specified is being used in a substitute".