Showing posts with label figure. Show all posts
Showing posts with label figure. Show all posts

Monday, March 26, 2012

Text file not being written using System.IO

I'm trying to figure out why when this runs, it runs with no errors but I'm not seeing a txt file outputed to the location I specified. I've replaced some of the filepath with sss for privacy purposes. If the compiler isn't giving any errors, then why isn't it creating the text file? All I see happens is the windows form defined in my code pops up...do I even need that if this is gonna be run as a scheduled task anyway?

What should I look at?


Imports System.IO

Public Class Form1
Inherits System.Windows.Forms.Form
Public Shared Sub Main()
Try
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New StreamReader("\\sss\f$\inetpub\wwwroot\sss\ssis\maintenance\sss\phase2\sss_input\sss_input.txt")
Dim input As String
input = sr.ReadLine()
While Not input Is Nothing

Dim sw As StreamWriter = New StreamWriter("\\sss\f$\inetpub\wwwroot\sss\ssis\maintenance\sss\phase2\sss_output\sss_output_test.txt")
sw.Write(input)
sw.Close()

End While

Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
End Sub
End Class

I am not really following the logic there, especially the part where you are saying: "if input is nothing" (if that is the check to see if the file exists, System.IO.File.Exists is a much much better way of checking that)

Outside of that failure to follow your logic, try using a less complicated path to try to write to... for instance, try using "c:\temp", which is local to your application and your app probably has write permissions there... what will this do?
- Well, if your app works, then this tells you that the problem you are hitting is more than likely related to permissions on the other machine
- If your app still doesn't work, something is amiss with your code

Thursday, March 22, 2012

textarea (multi line) how to set default value ?

Hi,
I cannot figure out how to set the default value for a <textarea> control in my page:

Here is my current code for this control:

<textarea name="contMessage" cols="35" rows="5" id="contMessage" runat="server" tooltip="enter your message here" /></textarea
how do I add a default value for this multi-line text field?


<textarea name="contMessage" cols="35" rows="5" id="contMessage" runat="server" tooltip="enter your message here" />
THIS IS THE TEXT APEARING IN THE TEXTAREA
</textarea>

put the text in between the textarea tags like so...

<textarea name="contMessage" cols="35" rows="5" id="contMessage" runat="server" tooltip="enter your message here" />Place your default text here!!!</textarea


Thanks for the replies.

That does not work for me ? It just puts the text I have between the tags, next to the textarea field, not within it ?

I have found the following to accomplish what I'm after, but am a little confused still:

<asp:textbox Text="This text does show WITHIN the text box" textmode="MultiLine" columns="35" rows="5" id="contMessage" runat="server" tooltip="enter your message here" />Text here shows NEXT to the text box</asp:textbox

Is this just me ? Is there something going on in ther st of my form to have this effect?
you are confusing 2 things - textbox and htmltextarea - try this


<asp:TextBox id="Text1"
Text="This will show up in textbox"
TextMode="MultiLine"
Columns="50"
Rows="5"
runat="server"/>

In addition....
I'd like to bind some data collected from the querystring to the default content of the textbox I've tried:

<asp:textbox Text='<%# Response.Write(Request.QueryString("page")) %>' textmode="MultiLine" columns="35" rows="5" id="contMessage" runat="server" tooltip="enter your message here" /></asp:textbox>

but this produces an error:

Compiler Error Message: BC30518: Overload resolution failed because no accessible 'ToString' can be called with these arguments:
Remove the response.write.
thanks for that, but it still doesn't apear to work without the response.write :


<asp:textbox Text='<%#(Request.QueryString("page"))%>' TextMode="MultiLine" Columns="35" Rows="5" ID="contMessage" runat="server" ToolTip="enter your message here"></asp:textbox>

this does not display anything for me. the querystring does have the appropriate string, I have a basic text response.write on another part of the page that works fine, but not within the textbox.

and just to go back to the textarea option (I'm not sure of the difference yet, but I can google that), is it just me who can't get a default value in the textarea by adding text in between the tags ? I just get that text next to the text box, not within it ?

any further help appreciated.
Im not sure how to do it that way ( still lookin around) but you can do it this way..
add the text assignment to the page load...

Sub Page_Load(Source As Object, E As EventArgs)
text1.text=request.querystring("page")
End Sub

aslo here are some links i use..
http://samples.gotdotnet.com/quickstart/aspplus/doc/webcontrolsref.aspx

text is a .Net WEBcontrol
textarea is a HTMLcontrol

I also refer to this
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/cpref_start.asp

most of the controls you will use are under System.Web.UI.controls on left panel

HTH