471,338 Members | 1,119 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Setting Filename to a text field

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
4 2039
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
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
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
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.

Similar topics

3 posts views Thread by John Flynn | last post: by
5 posts views Thread by Ariel Dolan | last post: by
15 posts views Thread by tshad | last post: by
3 posts views Thread by UJ | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.