Advertisement
Guest User

fileNameValidity using try and catch.

a guest
Dec 27th, 2011
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.62 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement