Accessing a .txt file that is a resource file. - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Accessing a .txt file that is a resource file.

Last post 04-06-2012 11:56 AM by Hilary Stoupa. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 04-06-2012 11:07 AM

    Accessing a .txt file that is a resource file.

    Is there a way to use code to access a txt file that is a resource file for a form.

    If not, is there a better way that I should be doing this?

    I need to read in a txt file, parse it, and then allow a user to save the finished product.

    I am able to read in the file from a network location but I'd much rather have the txt file as a part of the form in one way or another.

    Any suggestions would be greatly appreciated!

  • 04-06-2012 11:21 AM In reply to

    Re: Accessing a .txt file that is a resource file.

    So the text file doesn't change? Once you add it as a resource to the form, you'd need to update the file in the template if it had any changes....

    Any reason you'd not use an XML file and create a data connection to it? Then you may not have to use code at all...

    Hilary Stoupa

  • 04-06-2012 11:26 AM In reply to

    Re: Accessing a .txt file that is a resource file.

    The text files are already in place and quite lengthy. They will change frequently so I think it would be best to just be able to update the resource file with the new versions. I tried adding it as a resource file but wasn't too sure what to use for the pathname in the code.

    As of now I am just using the name of the file since I figured if it is part of the template, that should be enough to access it.

  • 04-06-2012 11:35 AM In reply to

    Re: Accessing a .txt file that is a resource file.

    Oh, I see - I think you are asking if it is possible to change the contents of a resource file in a form template programatically?

    You can access the file, but I don't think you'll be able to save the changes - you'd have to save the template as source files, and update the file, then repack it up.

    It sounds like your current approach of accessing the files from their network location may be the correct way to go here.

    To open a resource file that is part of your template (MSDN link):

    this.Template.OpenFileFromPackage("FileName.txt");

    Hilary Stoupa

  • 04-06-2012 11:45 AM In reply to

    Re: Accessing a .txt file that is a resource file.

    Thanks Hilary! Thats what I was looking for.

    I want to just open it then write to an output file that the user can save on their computer. I can do it without a prompt, but I will be looking into getting a save prompt to come up so they can name it and save it.

    This is definitely a start. Thanks again.

  • 04-06-2012 11:56 AM In reply to

    Re: Accessing a .txt file that is a resource file.

    Assuming this is not a browser form, you should be able to use a button and a SaveFileDialog - more at this link:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx

    Hilary Stoupa

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.