How do I save a stream to a file in C#?

As highlighted by Tilendor in Jon Skeet’s answer, streams have a CopyTo method since .NET 4. var fileStream = File.Create(“C:\\Path\\To\\File”); myOtherObject.InputStream.Seek(0, SeekOrigin.Begin); myOtherObject.InputStream.CopyTo(fileStream); fileStream.Close(); Or with the using syntax: using (var fileStream = File.Create(“C:\\Path\\To\\File”)) { myOtherObject.InputStream.Seek(0, SeekOrigin.Begin); myOtherObject.InputStream.CopyTo(fileStream); }

How can I get the assembly file version

See my comment above asking for clarification on what you really want. Hopefully this is it: System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion;

Pass Method as Parameter using C#

You can use the Func delegate in .net 3.5 as the parameter in your RunTheMethod method. The Func delegate allows you to specify a method that takes a number of parameters of a specific type and returns a single argument of a specific type. Here is an example that should work: public class Class1 { … Read more

Error – Unable to access the IIS metabase

On Windows 8 Pro: %systemroot%\inetsrv\config On Windows 7 and 8.1 and 10 %systemroot%\System32\inetsrv\config (Where %systemroot% is usually C:\Windows) Navigate to the appropriate location above in Windows Explorer. You will be blocked access with a popup which says: “You don’t have access to this folder – Click continue to permanently get access to this folder” Click … Read more

How to create a new object instance from a Type

The Activator class within the root System namespace is pretty powerful. There are a lot of overloads for passing parameters to the constructor and such. Check out the documentation at: http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx or (new path) https://docs.microsoft.com/en-us/dotnet/api/system.activator.createinstance Here are some simple examples: ObjectType instance = (ObjectType)Activator.CreateInstance(objectType); ObjectType instance = (ObjectType)Activator.CreateInstance(“MyAssembly”,”MyNamespace.ObjectType”);

Metadata file ‘.dll’ could not be found

I just had the same problem. Visual Studio isn’t building the project that’s being referenced. Written Instructions: Right click on the solution and click Properties. Click Configuration on the left. Make sure the check box under “Build” for the project it can’t find is checked. If it is already checked, uncheck, hit apply and check … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)