By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,567 Members | 1,605 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,567 IT Pros & Developers. It's quick & easy.

Setting Filename to a text field

P: n/a
Below code extracts the attachment and store it a share with actual
attachment name. How can I set filename to a text field's value in my
infopath form? So if attached file name is FileA.txt but the value in a text
field (FinalName) in form is FileXYZ.txt, file should be save to share as
FileXYZ.txt
-----------------------------------------------------------------------------------------------------
public void Submit_Clicked(object sender, ClickedEventArgs e)
{

// Write your code here.

XPathNavigator docXN = this.CreateNavigator();

XPathNavigator opnXN = docXN.SelectSingleNode("/my:myFields/my:Attachment",
this.NamespaceManager);

byte[] attachmentNodeBytes = Convert.FromBase64String(opnXN.ToString());

int fnLength = attachmentNodeBytes[20] * 2;

byte[] fnBytes = new byte[fnLength];

for (int i = 0; i < fnBytes.Length; i++)

{

fnBytes[i] = attachmentNodeBytes[24 + i];

}

char[] charFileName = System.Text.UnicodeEncoding.Unicode.GetChars(fnByt es);

string fileName = new string(charFileName);

fileName = fileName.Substring(0, fileName.Length - 1);

byte[] fileContents = new byte[attachmentNodeBytes.Length - (24 +
fnLength)];

for (int i = 0; i < fileContents.Length; ++i)

{

fileContents[i] = attachmentNodeBytes[24 + fnLength + i];

}

// Below is for storing to a Share

FileStream fs = new FileStream(@\\Server\EmpFiles\ + fileName,
FileMode.Create);

fs.Write(fileContents, 0, fileContents.Length); fs.Close();

----------------------------------------------------------------------------------------------------
Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Thu, 26 Jun 2008 11:15:57 -0700, andyoye <an*****@nospam.comwrote:
Below code extracts the attachment and store it a share with actual
attachment name. How can I set filename to a text field's value in my
infopath form? So if attached file name is FileA.txt but the value in a
text
field (FinalName) in form is FileXYZ.txt, file should be save to share as
FileXYZ.txt
Just use the value from your text field rather than from the file
attachment when you initialize the "fileName" variable.

Pete
Jun 27 '08 #2

P: n/a
How can I initialize "fileName" to get the value of form text field
"FinalName"

Thanks
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Thu, 26 Jun 2008 11:15:57 -0700, andyoye <an*****@nospam.comwrote:
>Below code extracts the attachment and store it a share with actual
attachment name. How can I set filename to a text field's value in my
infopath form? So if attached file name is FileA.txt but the value in a
text
field (FinalName) in form is FileXYZ.txt, file should be save to share as
FileXYZ.txt

Just use the value from your text field rather than from the file
attachment when you initialize the "fileName" variable.

Pete

Jun 27 '08 #3

P: n/a
On Jun 27, 12:42*pm, "andyoye" <andy...@nospam.comwrote:
How can I initialize "fileName" to get the value of *form text field
"FinalName"
fileName = FinalName.Text;

?

Jon
Jun 27 '08 #4

P: n/a
On Fri, 27 Jun 2008 10:33:49 -0700, andyoye <an*****@nospam.comwrote:
"FinalName" is the ID of infopath "text box" control node/field.
For what it's worth, it appears that your REAL question was "how do I get
the string value from an InfoPath 'text box' control?"

All that other stuff is just irrelevant.

You will find that you get your answers much more quickly, and much more
accurately, if you ask the questions correctly. :)

Pete
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.