locked
Expression Blend read text file RRS feed

  • Question

  • I have a project that needs Expression Blend to read a text file from the hard drive and enter it in a TextBlock with code-behind.

     

    Thanks for your help in advance.

    • Moved by Alan_chen Thursday, December 16, 2010 7:31 AM Expression (From:Visual C# Language)
    Wednesday, December 15, 2010 10:58 PM

Answers

  • Try the following:
    string strContent = "FilePath" + ".txt";
    
     WebClient client = new WebClient(); 
          client.OpenReadAsync(new Uri(strContent, UriKind.Relative)); 
          client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
    

    Then you have to create the Method cleint_OpenReadCompleted

    void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
      if (e.Error != null)
      {
       StreamReader myReader = new StreamReader(e.Result);
       string strLine = string.Empty;
       while ((strLine = myReader.ReadLine()) != null)
       {
        //Loop through all lines and fill up the Textbox
       }
      }
      
    }
    • Proposed as answer by Stef S Thursday, December 16, 2010 1:06 PM
    • Marked as answer by David32 Friday, December 17, 2010 7:59 PM
    Thursday, December 16, 2010 1:05 PM
  • Could you post the xaml and code you are using?

     

    The name "mytextblock" needs to be the value set the x:Name="" on the textblock.

    So in your SL app, you want to read a file from the user's machine? Or a file you as the developer provide?

     

    • Marked as answer by David32 Friday, December 17, 2010 7:59 PM
    Friday, December 17, 2010 5:35 PM
    Moderator

All replies

  • Try http://social.expression.microsoft.com/forums/en-US/blend/threads/.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Thursday, December 16, 2010 12:19 AM
  •  Hi David32,

    Welcome to MSDN forums.

    I agree with @Sheng Jiang, I think you may post inappropriate place,

    It’s like to get quicker and better responses to Expression Blend forums at http://social.expression.microsoft.com/forums/en-US/blend/threads  where experts live in.

    I will move your post to this forum.

    Thanks for understanding.

     

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 16, 2010 7:02 AM
  • Try the following:
    string strContent = "FilePath" + ".txt";
    
     WebClient client = new WebClient(); 
          client.OpenReadAsync(new Uri(strContent, UriKind.Relative)); 
          client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
    

    Then you have to create the Method cleint_OpenReadCompleted

    void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
      if (e.Error != null)
      {
       StreamReader myReader = new StreamReader(e.Result);
       string strLine = string.Empty;
       while ((strLine = myReader.ReadLine()) != null)
       {
        //Loop through all lines and fill up the Textbox
       }
      }
      
    }
    • Proposed as answer by Stef S Thursday, December 16, 2010 1:06 PM
    • Marked as answer by David32 Friday, December 17, 2010 7:59 PM
    Thursday, December 16, 2010 1:05 PM
  • Are you creating a WPF or Silverlight app?  WPF can access the local hard drive, Silverlight can't, so the answer depends on which types of project you are creating.
    Thursday, December 16, 2010 2:32 PM
    Moderator
  • hm ... on user initialized actions silverlight gets access to the local harddrive (using OpenFileDialog). But it has significant restrictions and limitations.
    Thursday, December 16, 2010 3:54 PM
  • Thanks for you answers. That will read from the hard drive. It's a silverlight application. I don't wont or need the user to change the text block.

    I believe I need to be a little more specific with my question, after I read from the hard drive I'm trying to set my text block from code-behind.

    mytextblock.text= "This is some text I want to put in the text block."

    Visual studio does not reconize mytextblock as valid, even though it is the name of my textblock, and doesn't work when I run the app.

    • Proposed as answer by acidreflux Friday, December 17, 2010 9:50 PM
    Friday, December 17, 2010 5:19 PM
  • Could you post the xaml and code you are using?

     

    The name "mytextblock" needs to be the value set the x:Name="" on the textblock.

    So in your SL app, you want to read a file from the user's machine? Or a file you as the developer provide?

     

    • Marked as answer by David32 Friday, December 17, 2010 7:59 PM
    Friday, December 17, 2010 5:35 PM
    Moderator
  • The app is supposed to provide information to the viewer of the web page, and I want to make it easy to update by simply uploading a new text file with the same name from time to time. So the file will come form the web server. The name is now showing up in visual studio and I'm able to set the text block. Thanks!

    Friday, December 17, 2010 7:59 PM