Sunday, April 3, 2011

Solution for System.IO.IOException: The device is not ready. error

Many times our applications refer a file on disk. At the time of development, most of the developers refer to the file by it's absolute path.

The trap here is, the absolute path on the development environment most of the times differ from the path on the deployment server. So though you're able to build and ship the DLLs you will always encounter a runtime error. Thats simply because the AppDomain is not able to locate the file from the path you mentioned. Moreover, the path does not exist in itself :P

So to get rid of this scenario always use Server.MapPath which would resolve the file path on the server. Also refer the url below for code snippets.
Server.MapPath example

Happy Coding :)

1 comment:

Unknown said...

Very thanks! It's important