dcsimg
Results 1 to 2 of 2

Thread: the name "My" does not exist in current context

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    69

    the name "My" does not exist in current context

    I am trying to make a program to auto move text file in the location i choose. it works well in vb.net but when i tried to code in c# it shows error the name "My" does not exist in current context.

    can anyone help me how can i convert that to c# ?
    code with error:
    Code:
      My.Computer.FileSystem.CopyFile(file, txtReadPath.Text + @"\" + fName, overwrite: false);
    whole code
    Code:
     
    
      private void button5_Click(object sender, EventArgs e)
            {
                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                {
                    txtReadPath.Text = folderBrowserDialog1.SelectedPath;
                }
            }
    
            //search file methods
            public void SearchFiles(string Pattern, string Path, ArrayList FilesFound)
            {
                FilesFound.AddRange(Directory.GetFiles(Path, Pattern));
            }
    
    private void timer1_Tick(object sender, EventArgs e)
            {
                ArrayList files = new ArrayList();
                SearchFiles("*", txtReadPath.Text, files);
                foreach (string file in files)
                {   
                    string fName = Path.GetFileName(file);
                    My.Computer.FileSystem.CopyFile(file, txtReadPath.Text + @"\" + fName, overwrite: false);
                    
                }
    
            }

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,788

    Re: the name "My" does not exist in current context

    The My namespace is VB-specific. Some of what's under there just duplicates other functionality in the Framework and so can be easily replaced in both VB and C#. Some of it is not a direct copy.

    That FileSystem.CopyFile method is an interesting one because it falls into both categories. The overloads with parameter lists of (String, String) and (String, String, Boolean) can be replaced with File.Copy from System.IO. You're calling that second overload so you're good to go. The other overloads actually use Windows shell functionality, e.g. the Windows file copy progress dialogue, so there is no direct replacement in C#.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width