Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if resource exists

Tags:

c#

.net

I want to check if a resource key exists before get it from resources. I use TemplateControl.GetGlobalResourceObject to get the resource.

Is it possible?

Thank you.

like image 472
rpf Avatar asked Oct 06 '11 18:10

rpf


People also ask

How to check if resource exists in java?

Java provides a simple boolean method, file. exists() that doesn't require any parameters to check the relevant file on a given path.

Which http check resource URI exists?

Java Language HttpURLConnection Check if resource exists If you are just checking if a resource exists, it better to use a HEAD request than a GET. This avoids the overhead of transferring the resource. Note that the method only returns true if the response code is 200 .

How do I know if a file is in classpath?

To find a file in the classpath we have created a method, File findFileOnClassPath(final String fileName) that reads a fileName and returns the File. The method is described below: It uses the System. getProperty(String key) to find the classpath of java and the path separator used.


1 Answers

GetGlobalResourceObject returns object type. You can always check if it is null before you cast it (to a string for example) and use it in subsequent logic.

Be careful that (string)TemplateControl.GetGlobalResourceObject will throw an InvalidCastException that needs to be handled.

For reference: TemplateControl.GetGlobalResourceObject Method (String, String)

like image 149
Anas Karkoukli Avatar answered Oct 12 '22 05:10

Anas Karkoukli