Asked by:
How to check if file is exist in RDLC (by Report Builder 2.0)?

Question
-
User1997404758 posted
I have an rdlc. i want to check if file is exists - if then - so insert an image, else, insert other image.
i tried to use an method as:
Public Function FileIsExists(ByVal filePath As String) As Boolean If System.IO.File.Exists(filePath) = True Then Return True Else : Return False End If End Function
but it's method always return false.. also for exists files..
Saturday, November 19, 2011 6:51 AM
All replies
-
User-434868552 posted
@ kondor
(a) System.IO.File.Exists(filePath) returns a boolean, so you do not need "- True"
(b) your code looks good, so your problem is likely the value of "filePath" ...
use the debugger and/or display the value of "filePath"(c) unless you intend to add additional features to your function, it is redundant because you can write your "If System.IO.File.Exists" inline.
g.
Saturday, November 19, 2011 3:28 PM -
User1997404758 posted
right, the correct method is:
Public Function FileIsExists(ByVal filePath As String) As Boolean Return System.IO.File.Exists(filePath) End Function
but it always return false,
how to can i to debug?
it's a RDLC file that use this method??it's possible to attach a file to here? for illustrate that?Saturday, November 19, 2011 3:39 PM -
User-434868552 posted
@ kondor
file type does not matter; System.IO.File.Exists is file type agnostic ...
other causes may be that you do not have the appropriate access rights to the file.
use the debugger ... it you do not know how to use the debugger, this article may help: http://www.codeproject.com/KB/cs/MasteringInDebugging.aspx
g.
Saturday, November 19, 2011 4:00 PM -
User1997404758 posted
I think there's some confusion.
This is RDLC file - which was created through the Report Builder 2.0 -
Not through VS.
VS does not know debug RDLC file..Saturday, November 19, 2011 4:06 PM -
User-434868552 posted
@ kondor
Perhaps i do not understand your goals ... if you are simply trying to determine whether a file exists, the .NET Framework serves that purpose.
This code runs in LINQPad 4:
Sub Main If FileIsExists("c:\windows\system32\notepad.exe") Then Debug.Print("Found It") Else Debug.Print("Lost it") End If If FileIsExists("c:\windows\system32\MeaningOfLife.exe") Then Debug.Print("Life has meaning") Else Debug.Print("Life is meaningless") End If End Sub Public Function FileIsExists(ByVal filePath As String) As Boolean Return System.IO.File.Exists(filePath) End Function
it produces this output
Found It Life is meaningless
N.B.: this is simpler (If System.IO.File.Exists is inline where it belongs in most cases):
Sub Main If System.IO.File.Exists("c:\windows\system32\notepad.exe") Then Debug.Print("Found It") Else Debug.Print("Lost it") End If If System.IO.File.Exists("c:\windows\system32\MeaningOfLife.exe") Then Debug.Print("Life has meaning") Else Debug.Print("Life is meaningless") End If End Sub
g.
Saturday, November 19, 2011 4:18 PM