Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem with code

Problem with code

Scheduled Pinned Locked Moved ASP.NET
visual-studiosysadminhelp
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Girish481
    wrote on last edited by
    #1

    Hello, I am using VS 2005 and following is the code: Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim fp As StreamWriter Dim line As String Dim filename As String = System.Guid.NewGuid.ToString & ".Txt" Try fp = File.CreateText(Server.MapPath(filename)) line = "Normal Text" & Chr(27) & "E" & " Bold Text" & Chr(27) & "F" fp.WriteLine(line) line = "Normal " & Chr(27) & "S 0" & " It should be superscript" & Chr(27) & "T" fp.WriteLine(line) fp.WriteLine(Chr(27) & "4" & " Italic Mode" & Chr(27) & "5") ' Italic mode fp.WriteLine(Chr(20) & " or it should be superscript " & Chr(20) & "Normal") fp.WriteLine(Chr(15) & "Girish Kumar Sharma" & Chr(18)) ' condensed mode 'fp.WriteLine(Chr(12)) ' Page Eject fp.Close() Catch err As Exception err.ToString() Finally End Try Dim fpforbat As StreamWriter Dim strFilePath As String = "c:\\temp\\" & System.Guid.NewGuid.ToString & ".Bat" fpforbat = File.CreateText(strFilePath) Dim x As String = "Type " & Chr(34) & Server.MapPath(filename) & Chr(34) & " > PRN" fpforbat.WriteLine(x) fpforbat.Close() 'Dim strFilePath As String = "c:\\temp\\test.bat" Dim psi As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd.exe") psi.UseShellExecute = False psi.RedirectStandardOutput = True psi.RedirectStandardInput = True psi.RedirectStandardError = True psi.WorkingDirectory = "c:\\temp\\" Dim proc As System.Diagnostics.Process = System.Diagnostics.Process.Start(psi) Dim strm As System.IO.StreamReader = System.IO.File.OpenText(strFilePath) Dim sout As System.IO.StreamReader = proc.StandardOutput Dim sin As System.IO.StreamWriter = proc.StandardInput While strm.Peek() <> -1 sin.WriteLine(strm.ReadLine()) End While strm.Close() Dim stEchoFmt As String = "# {0} run successfully. Exiting" sin.WriteLine(String.Format(stEchoFmt, strFilePath)) sin.WriteLine("EXIT") proc.Close() sin.Close() sout.Close() 'File.Dele

    C 1 Reply Last reply
    0
    • G Girish481

      Hello, I am using VS 2005 and following is the code: Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim fp As StreamWriter Dim line As String Dim filename As String = System.Guid.NewGuid.ToString & ".Txt" Try fp = File.CreateText(Server.MapPath(filename)) line = "Normal Text" & Chr(27) & "E" & " Bold Text" & Chr(27) & "F" fp.WriteLine(line) line = "Normal " & Chr(27) & "S 0" & " It should be superscript" & Chr(27) & "T" fp.WriteLine(line) fp.WriteLine(Chr(27) & "4" & " Italic Mode" & Chr(27) & "5") ' Italic mode fp.WriteLine(Chr(20) & " or it should be superscript " & Chr(20) & "Normal") fp.WriteLine(Chr(15) & "Girish Kumar Sharma" & Chr(18)) ' condensed mode 'fp.WriteLine(Chr(12)) ' Page Eject fp.Close() Catch err As Exception err.ToString() Finally End Try Dim fpforbat As StreamWriter Dim strFilePath As String = "c:\\temp\\" & System.Guid.NewGuid.ToString & ".Bat" fpforbat = File.CreateText(strFilePath) Dim x As String = "Type " & Chr(34) & Server.MapPath(filename) & Chr(34) & " > PRN" fpforbat.WriteLine(x) fpforbat.Close() 'Dim strFilePath As String = "c:\\temp\\test.bat" Dim psi As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd.exe") psi.UseShellExecute = False psi.RedirectStandardOutput = True psi.RedirectStandardInput = True psi.RedirectStandardError = True psi.WorkingDirectory = "c:\\temp\\" Dim proc As System.Diagnostics.Process = System.Diagnostics.Process.Start(psi) Dim strm As System.IO.StreamReader = System.IO.File.OpenText(strFilePath) Dim sout As System.IO.StreamReader = proc.StandardOutput Dim sin As System.IO.StreamWriter = proc.StandardInput While strm.Peek() <> -1 sin.WriteLine(strm.ReadLine()) End While strm.Close() Dim stEchoFmt As String = "# {0} run successfully. Exiting" sin.WriteLine(String.Format(stEchoFmt, strFilePath)) sin.WriteLine("EXIT") proc.Close() sin.Close() sout.Close() 'File.Dele

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Wow - what a nightmare this is. What are you trying to do ? Does this cause things to print on the print ? Why do you want to write code that prints stuff on the server ?

      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

      G 1 Reply Last reply
      0
      • C Christian Graus

        Wow - what a nightmare this is. What are you trying to do ? Does this cause things to print on the print ? Why do you want to write code that prints stuff on the server ?

        Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

        G Offline
        G Offline
        Girish481
        wrote on last edited by
        #3

        Sir, Thanks for your reply. From the above code, i am creating a formated text file and one batch file which will be print the formated text file by using dos mode i.e. > PRN; but sir, problem is that if i wish to delete the formated and/or batch file, after run the code, i am not able to do so. Regards Girish Sharma

        C 1 Reply Last reply
        0
        • G Girish481

          Sir, Thanks for your reply. From the above code, i am creating a formated text file and one batch file which will be print the formated text file by using dos mode i.e. > PRN; but sir, problem is that if i wish to delete the formated and/or batch file, after run the code, i am not able to do so. Regards Girish Sharma

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I repeat. Why do you want to emit a printout on the server ?

          Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

          G 1 Reply Last reply
          0
          • C Christian Graus

            I repeat. Why do you want to emit a printout on the server ?

            Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

            G Offline
            G Offline
            Girish481
            wrote on last edited by
            #5

            I do'nt know, how to create the text file on client's machine; and what is another way to get the DOS mode (which runs faster) printing of a text file by asp.net, so please guide/help me in this regard. Regards Girish Sharma

            S 1 Reply Last reply
            0
            • G Girish481

              I do'nt know, how to create the text file on client's machine; and what is another way to get the DOS mode (which runs faster) printing of a text file by asp.net, so please guide/help me in this regard. Regards Girish Sharma

              S Offline
              S Offline
              saini arun
              wrote on last edited by
              #6

              The thing Christian wants to point out is that your application will use the printer installed on the server where you application is running. It means, every time the printout will be generated by the printer installed on the server, not on the machine from where you are accessing the web page.

              G 1 Reply Last reply
              0
              • S saini arun

                The thing Christian wants to point out is that your application will use the printer installed on the server where you application is running. It means, every time the printout will be generated by the printer installed on the server, not on the machine from where you are accessing the web page.

                G Offline
                G Offline
                Girish481
                wrote on last edited by
                #7

                At the first stage if it runs on server machine and printer; then my question will be how to access and client's printer to get printout. Actually, this is running fine on server printer but if i remove the comment from any of last two line i.e. 'File.Delete(Server.MapPath(".") & "\" & filename) 'File.Delete(strFilePath) then no print out comes on the printer. Please help me. Regards Girish Sharma

                D C 2 Replies Last reply
                0
                • G Girish481

                  At the first stage if it runs on server machine and printer; then my question will be how to access and client's printer to get printout. Actually, this is running fine on server printer but if i remove the comment from any of last two line i.e. 'File.Delete(Server.MapPath(".") & "\" & filename) 'File.Delete(strFilePath) then no print out comes on the printer. Please help me. Regards Girish Sharma

                  D Offline
                  D Offline
                  DoctorMick
                  wrote on last edited by
                  #8

                  That may be because the print command hasn't finished when you delete the file but it isn't important if you want to print on the client machine anyway. Look into the javascript function window.print if you need to print client side.

                  1 Reply Last reply
                  0
                  • G Girish481

                    At the first stage if it runs on server machine and printer; then my question will be how to access and client's printer to get printout. Actually, this is running fine on server printer but if i remove the comment from any of last two line i.e. 'File.Delete(Server.MapPath(".") & "\" & filename) 'File.Delete(strFilePath) then no print out comes on the printer. Please help me. Regards Girish Sharma

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    None of this matters, you moron. You're printing on the server. Don't you read ? If you want to print on the client, none of the hideously ugly code you posted, will do that, nor is it possible to print in ASP.NET in any direct way through your code behind. Buy a basic ASP.NET book and read it, it's clear you have no idea what server side code is.

                    Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

                    G 1 Reply Last reply
                    0
                    • C Christian Graus

                      None of this matters, you moron. You're printing on the server. Don't you read ? If you want to print on the client, none of the hideously ugly code you posted, will do that, nor is it possible to print in ASP.NET in any direct way through your code behind. Buy a basic ASP.NET book and read it, it's clear you have no idea what server side code is.

                      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

                      G Offline
                      G Offline
                      Girish481
                      wrote on last edited by
                      #10

                      Sir, I created the required formated text file with the help of above code. Now i wish to get print on Line Matrix Printer in DOS mode; so i read that it can be achieved by run a batch file. If it is not possible with the above code then; how do i print (DOS Mode) the generated text file at client machine on the click of a button in the web page, with the help of window.print and/or by any other mean please. If you please provide me any link i shall be highly thankful to you. Best Regards Girish Sharma

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups