Setting Filename to a text field

A

andyoye

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 = attachmentNodeBytes[24 + i];

}

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

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 = 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();

----------------------------------------------------------------------------------------------------
 
A

andyoye

How can I initialize "fileName" to get the value of form text field
"FinalName"

Thanks
 
A

andyoye

"FinalName" is the ID of infopath "text box" control node/field.


How can I initialize "fileName" to get the value of form text field
"FinalName"

fileName = FinalName.Text;

?

Jon
 
K

Kalpesh

Hi,

Assuming Infopath form is like a webform, you could write

fileName = txtFileName.Text;

Where, txtFileName is the name of the textbox control, which accepts
the filename

HTH
Kalpesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top