Is it possible to validate property of a ASP.NET UserControl at compile time..
e.g. ID="1" shows an error
I have a public property called 'UploadDirectory'
I want to show error message when the directory is not present..
I wrote following code for the public property but it works as expected at runtime only
Expand|Select|Wrap|Line Numbers
- /// <summary>
- /// Format e.g. ~/UploadDirectory/
- /// </summary>
- public string UploadDirectory
- {
- get { return _UploadDirectory; }
- set {
- if (!value.EndsWith("/"))
- {
- _UploadDirectory = value + "/";
- }
- else
- {
- _UploadDirectory = value;
- }
- if(!Directory.Exists(Server.MapPath(UploadDirectory)))
- {
- FileNotFoundException ex =new FileNotFoundException("The directory doesn't exists,\nPlease create the directory: " + UploadDirectory);
- ex.Source=this.Request.Url.AbsolutePath;
- throw ex;
- }
- }
- }
warm regards,
Nitin