• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 811
  • Last Modified:

Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:

Public Function SaveIt() As String
     
      Dim intCounter As Integer = 0
      Dim strNewPath = "D:\Data\MsOffice\Projects\Toll Connect\Postcodes\TCPostcodes\TollWorks.csv"
      Dim strHoldString As String
      Dim strWriter As StreamWriter

      Try
         'Create the file then write the records ....
         strWriter = New StreamWriter(strNewPath)

The above code is generating an error "Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:".   System.IO has been imported.   Can anyone please help?
0
bertpet
Asked:
bertpet
  • 3
  • 2
1 Solution
 
basicinstinctCommented:
I think the problem is that you are trying to pass the StreamWriter constructor a String, but it actually wants a FileStream object.

I think you should change it to something like this (I don't have .Net installed so I can't test it):


Public Function SaveIt() As String
     
      Dim intCounter As Integer = 0
      Dim strNewPath = "D:\Data\MsOffice\Projects\Toll Connect\Postcodes\TCPostcodes\TollWorks.csv"
      Dim strHoldString As String
      Dim strWriter As StreamWriter

      Try
         Dim fs as New FileStream(strNewPath, FileMode.Create, FileAccess.Write)
         strWriter = New StreamWriter(fs)



'declaring a FileStream and creating a word document file named file with
0
 
basicinstinctCommented:
By the way, good sample code here:

http://www.startvbdotnet.com/files/default.aspx
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Change this:

    Dim strNewPath = "D:\Data\MsOffice\Projects\Toll Connect\Postcodes\TCPostcodes\TollWorks.csv"

To:

    Dim strNewPath As String = "D:\Data\MsOffice\Projects\Toll Connect\Postcodes\TCPostcodes\TollWorks.csv"

and it should be happy then...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
basicinstinctCommented:
so the  constructor can handle a string?
0
 
bertpetAuthor Commented:
Dumbo (me that is).  Added the As String and it worked perfectly.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now