Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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?)
 
  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 6-Feb-13 4:45am
Comments
Sergey Alexandrovich Kryukov at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

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

  Print Answers RSS
0 DamithSL 495
1 Maciej Los 258
2 OriginalGriff 229
3 BillWoodruff 170
4 Zoltán Zörgő 165
0 OriginalGriff 7,934
1 DamithSL 6,084
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,174
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100