473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Showing build/compile time error

270 100+
Hi,
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
  1.     /// <summary>
  2.     /// Format e.g. ~/UploadDirectory/
  3.     /// </summary>
  4.     public string UploadDirectory
  5.     {
  6.         get { return _UploadDirectory; }
  7.         set {
  8.             if (!value.EndsWith("/"))
  9.             {
  10.                 _UploadDirectory = value + "/";
  11.             }
  12.             else
  13.             {
  14.                 _UploadDirectory = value;
  15.             }
  16.             if(!Directory.Exists(Server.MapPath(UploadDirectory)))
  17.             {
  18.                 FileNotFoundException ex =new FileNotFoundException("The directory doesn't exists,\nPlease create the directory: " + UploadDirectory);
  19.                 ex.Source=this.Request.Url.AbsolutePath;
  20.                 throw ex;
  21.             }
  22.         }
  23.     }
  24.  
Please help

warm regards,
Nitin
Jun 16 '10 #1
5 1299
ThatThatGuy
449 Expert 256MB
@NitinSawant
You certainly can't..

Although you can check it while debug
Jun 17 '10 #2
NitinSawant
270 100+
but then how it shows error for the other properties
e.g. ID="1"
Jun 17 '10 #3
ThatThatGuy
449 Expert 256MB
@NitinSawant
Where's the code... where you used ID property..
Jun 18 '10 #4
NitinSawant
270 100+
Here's the code of usercontrol in page:
Expand|Select|Wrap|Line Numbers
  1. <uc1:UserCtrl ID="MyCtrl1" UploadDirectory="~/TestDirectory/" runat="server" />
now I need to show error[at compile time] when the directory "TestDirectory" is not present..

Regards,
Nitin
Jun 18 '10 #5
Frinavale
9,735 Expert Mod 8TB
Have you tried using preprocessor directives?

For example:
Expand|Select|Wrap|Line Numbers
  1. #If ID = 1
  2.  'do code here
  3. #End If
-Frinny
Jun 21 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: A | last post by:
Hi, I created an array of user defined objects dynamically in a class Foo's constructor. class Foo{ Foo(){ Bar* b = new Bar(); }
8
by: Michael Gaab | last post by:
How would I force the compiler to throw an error for the following: function signature - void foo(short); function call - foo('d'); My compiler does not complain when I call foo() with a...
9
by: ThunderMusic | last post by:
Hi, I'd like to create a compile time error in my class... maybe there's a way already built in in the framework so I can achieve what I want... I have 2 constructors in my class. One of them...
9
by: Finger.Octopus | last post by:
I dont know whats terribly going wrong with this, well I know there's some memory allocation with this but I tried hard to fix it and when it gets fixed it doesn't shows up the desired value, this...
2
by: KiranJyothi | last post by:
Can anyone please tell me how can I rectify my compile time error in this program. /********************************HEADER FILE***********************************/ #ifndef POLYNOMIAL_H //...
5
by: fimarn | last post by:
I am trying to get rid of compile time error that I am getting only in RHEL5 (not in RHEL4) apparently due to the changes in the stl_list.h file. The error that I am getting is coming from the...
11
by: Bryan Crouse | last post by:
I am looking a way to do error checking on a string at compile time, and if the string isn't the correct length have then have the compiler throw an error. I am working an embedded software that...
4
by: cpptutor2000 | last post by:
Could someone please help me? I have the following C struct. typedef struct _FIREWALL_RULE_INFO { ULONG Precedence; BOOL bEnabled; BOOL ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.