Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
In a C# windows form app I had the following code...

using (SqlConnection cs = new SqlConnection(
@"Data Source=100-NUprod-P-001.acds.net;Initial Catalog=Nuprod;Persist Security Info=True;User ID=Nuprod;Password=MyPa$$word"))
            {
                cs.Open();


                using (SqlDataAdapter da = new SqlDataAdapter(@"Select top 25 stationipaddress From machines", cs))
                {
                     3
                     Use DataAdapter to fill DataTable
                    DataTable t = new DataTable();
                    da.Fill(t);

                     4
                     Render data onto the screen
                    dataGridView1.DataSource = t; // <-- From your designer
                }


                Thread.Sleep(2000);



                foreach (DataGridViewRow row in this.dataGridView1.Rows)
                {
                    try
                    {

                        foreach (DataGridViewCell cell in row.Cells)
                        {
                            if (!cell.Size.IsEmpty)
                            {


                                MessageBox.Show(cell.Value.ToString());


                                ProcessStartInfo startInfo = new ProcessStartInfo();
                                startInfo.FileName = "net.exe";
                                startInfo.Arguments = @"use \\" + cell.Value.ToString() + "\\c$" + " " + "Password /user:admin";
                                startInfo.UseShellExecute = false;
                                startInfo.RedirectStandardOutput = true;
                                startInfo.RedirectStandardInput = true;
                                startInfo.CreateNoWindow = true;
                                Process.Start(startInfo);

                                Thread.Sleep(1000);



                            }
                        }
                    }
                    catch (Exception)
                    {

                        MessageBox.Show("First Query Complete");
                        foreach (DataGridViewRow row1 in this.dataGridView1.Rows)
                        {
                            try
                            {

                                foreach (DataGridViewCell cell in row1.Cells)
                                {
                                    if (!cell.Size.IsEmpty)
                                    {

            

                                        int timeout = 5000;

           
                                        Process process = new Process();
                                        process.StartInfo.FileName = "xcopy";
                                        process.StartInfo.Arguments = textBox1.Text + " " + @"\\" + cell.Value.ToString() + @"\" + textBox2.Text + @"/C/Y/E/Q/F";
                                        process.StartInfo.UseShellExecute = false;
                                        process.StartInfo.RedirectStandardOutput = true;
                                        process.StartInfo.RedirectStandardInput = true;
                                        process.StartInfo.CreateNoWindow = true;
                                        process.Start();
                                        process.WaitForExit(timeout);

                                                                         
                                          
                                        
                                        



                                    }
                                }
                            }
                            catch (Exception)
                            {
                                

                                var compiler = new Process();
                                compiler.StartInfo.FileName = "net.exe";
                                compiler.StartInfo.Arguments = "use * /delete /Y";
                                compiler.StartInfo.UseShellExecute = true;
                                compiler.StartInfo.RedirectStandardOutput = false;
                                compiler.Start();

                                Thread.Sleep(1000);

                                MessageBox.Show("Part 1 Copy Done");
                                cs.Close();


                            }



                        }

                    }

                }


And then when I try to put it in my ASP.Net Web App I get the following errors with the following code.

Error 1 The type or namespace name 'GridViewCell' could not be found (are you missing a using directive or an assembly reference?)

C#
  using (SqlConnection cs = new SqlConnection(
@"Data Source=100-NUprod-P-001.acds.net;Initial Catalog=Nuprod;Persist Security Info=True;User ID=Nuprod;Password=MyPa$$word"))
            {
                cs.Open();


                using (SqlDataAdapter da = new SqlDataAdapter(@"Select top 25 stationipaddress From machines", cs))
                {
                     //3
                     //Use DataAdapter to fill DataTable
                    DataTable t = new DataTable();
                    da.Fill(t);

                     //4
                     //Render data onto the screen
                    GridView1.DataSource = t; // <-- From your designer
                }


                Thread.Sleep(2000);



                foreach (GridViewRow row in this.GridView1.Rows)
                {
                    try
                    {

                        foreach (GridViewCell cell in row.Cells)
                        {
                            if (!cell.Size.IsEmpty)
                            {


                                //MessageBox.Show(cell.Value.ToString());


                                ProcessStartInfo startInfo = new ProcessStartInfo();
                                startInfo.FileName = "net.exe";
                                startInfo.Arguments = @"use \\" + cell.Value.ToString() + "\\c$" + " " + "Password /user:admin";
                                startInfo.UseShellExecute = false;
                                startInfo.RedirectStandardOutput = true;
                                startInfo.RedirectStandardInput = true;
                                startInfo.CreateNoWindow = true;
                                Process.Start(startInfo);

                                Thread.Sleep(1000);



                            }
                        }
                    }
                    catch (Exception)
                    {

                        //MessageBox.Show("First Query Complete");
                        foreach (GridViewRow row1 in this.GridView1.Rows)
                        {
                            try
                            {

                                foreach (GridViewCell cell in row1.Cells)
                                {
                                    if (!cell.Size.IsEmpty)
                                    {

            

                                        int timeout = 5000;

           
                                        Process process = new Process();
                                        process.StartInfo.FileName = "xcopy";
                                        process.StartInfo.Arguments = textBox1.Text + " " + @"\\" + cell.Value.ToString() + @"\" + textBox2.Text + @"/C/Y/E/Q/F";
                                        process.StartInfo.UseShellExecute = false;
                                        process.StartInfo.RedirectStandardOutput = true;
                                        process.StartInfo.RedirectStandardInput = true;
                                        process.StartInfo.CreateNoWindow = true;
                                        process.Start();
                                        process.WaitForExit(timeout);

                                                                         
                                          
                                        
                                        



                                    }
                                }
                            }
                            catch (Exception)
                            {
                                

                                var compiler = new Process();
                                compiler.StartInfo.FileName = "net.exe";
                                compiler.StartInfo.Arguments = "use * /delete /Y";
                                compiler.StartInfo.UseShellExecute = true;
                                compiler.StartInfo.RedirectStandardOutput = false;
                                compiler.Start();

                                Thread.Sleep(1000);

                                //MessageBox.Show("Part 1 Copy Done");
                                cs.Close();


                            }



                        }

                    }

                }
Posted
Comments
Sergey Alexandrovich Kryukov 6-Feb-13 10:54am    
Who told you that you can use the code written to a somewhat similar but totally unrelated class?
Don't waste your time.
-SA

1 solution

Please see my comment to the question. Nothing from System.Windows.Forms can be used in ASP.NET.

Use System.Web.UI.WebControls.GridView with the help of its original documentation: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx[^].

Don't waste your time on thinking about using your old code.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900