0

I put a file on my Resources in my C# program. I try to open it in a specific app but don't understand how.

I already see this: .NET: Open files, which are embedded in a resource file

and this: Use embedded file from resources.resx in program

I need to open "TEST.rvt" (Autodesk Revit file), Which is an embedded resource, in Revit.exe

I don't want to copy the file to my system, so setting the Copy to Output Directory option is not possible.

Is it possible?

This is my little program

Thomas_LCP
  • 53
  • 7
  • How do you want to open it? See the contents of the file? Open it with Revit? What do you want to do with it? – funie200 Dec 01 '20 at 11:03
  • Open it with Revit yes. – Thomas_LCP Dec 01 '20 at 11:33
  • Alright, check this question: [c# open file with default application and parameters](https://stackoverflow.com/questions/11365984/c-sharp-open-file-with-default-application-and-parameters) – funie200 Dec 01 '20 at 12:10
  • It doesn't work with EMBEDDED file. – Thomas_LCP Dec 01 '20 at 12:14
  • Maybe [this](https://stackoverflow.com/a/8609536/8873143) helps, even if its for a PDF – funie200 Dec 01 '20 at 12:24
  • In the answers of this post Adam say "In order for this to work, the Visual Studio setting Copy to Output Directory has to be set to Copy Always for the PDF file." I do not want this. I do not want to copy the file on Windows .. – Thomas_LCP Dec 01 '20 at 12:27

2 Answers2

1

As I can read on many thread in the internet, it seem to be impossible. I will copy my .rvt in a temp folder and delete it just before using them.

To copy them I use the solution from this thread

Thomas_LCP
  • 53
  • 7
0

I don't have Revit so I don't know if this will work. But without setting Copy to Output Directory the following seems to work for a .txt file in Notepad.

string textFile = Properties.Resources.Testfile;

Process process = new Process();
process.StartInfo.FileName = "Notepad.exe"; // Set this to Revit.exe or whatever name it has
process.StartInfo.Arguments = textFile;
process.Start();

Properties.Resources.Testfile is the embedded .txt file in the project.

I don't know what a .rvt file looks like so I don't know if this will work correctly.

funie200
  • 3,688
  • 5
  • 21
  • 34
  • .rvt seem to be a byte[] so it will not work :/ https://prnt.sc/vto4dt – Thomas_LCP Dec 01 '20 at 15:02
  • return me "cannot find the specified file" as you can see https://prnt.sc/vto75d I think convertion from byte[] to string is a bad idea :) – Thomas_LCP Dec 01 '20 at 15:06
  • Just as a test, does `File.WriteAllBytes(Properties.Resources.TEST, Encoding.Unicode.GetBytes(Properties.Resources.TEST));` work before doing the `Process` stuff? I think it does override the file thought :/ And maybe `Unicode` isn't the best idea here as well. – funie200 Dec 01 '20 at 15:10
  • Maybe I can just give a byte[] instead of the string. Maybe Revit.exe can understand this type of argument instead of a string. I'm also trying your solution. – Thomas_LCP Dec 02 '20 at 09:57