SHARE
TWEET

fileNameValidity using try and catch.

a guest Dec 27th, 2011 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     Public Function isFileNameValid(ByVal fileName As String)
  2.         Dim isValid As Boolean = False
  3.  
  4.         Try
  5.             IO.File.WriteAllText(fileName, "")
  6.             IO.File.Delete(fileName)
  7.             isValid = True
  8.         Catch ex As Exception
  9.             isValid = False
  10.         End Try
  11.  
  12.         Return isValid
  13.     End Function
  14.  
  15. '-------------------------
  16.  
  17. sub writeFileWhenThisHappens()
  18.         dim content as string = "this text goes into the file"
  19.  
  20.         if isFileNameValid(textFieldWhereUserWritesTheFilename.text) then
  21.                 IO.File.WriteAllText(textFieldWhereUserWritesTheFilename.text, content)
  22.         end if
  23.  
  24. end sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top