Publishing an InfoPath

S

sadhana

Hi,
Is it possible to publish an InfoPath's data programmatically?
My task is that, I have some checkboxes and corresponding file
attachments(infopaths). when a user selects a checkbox and clicks on a
button, that file attachement (infopath) should be published to sharepoint
server document library.
Can we do it programmatically?

Thanks in advance
Sadhana
 
S

SSA

Just publish the form programmatically and everything in the form will
automatically be submitted. You may use the following code to submit:

public void FormEvents_Submit(object sender, SubmitEventArgs e)
{

FileSubmitConnection fc =
(FileSubmitConnection)this.DataConnections["Main submit"];
// Modify the URL we want to submit to by concatenating the
string dLocation = this.Location.ToString();
fc.FolderUrl = dLocation.Substring(0, dLocation.LastIndexOf("/"));

// Execute the submit connection
try
{

fc.Execute();

e.CancelableArgs.Cancel = false;

}

catch (Exception ex)
{

e.CancelableArgs.Cancel = true;
}

Location is a local variable. You can skip it and use the following line
instead:

string dLocation = "http://server/dolib/forms/AllItems.aspx"; --> This is
just a sample, use the exact complete library URL here and you can also
capture the url programmatically. For example,

dLocation = this.Template.Uri.ToString();

Hope this helps

SSA
MOSS MVP
 
S

sadhana

Hi,

What is this "Main Submit" in Data Connections?
Is it a dataconnection library in sharepoint server or just a dataconnection
to submit data? even, I tried it in both cases, it is not working.
and what is this "Location" in the program. I have given the URL directly at
the dlocation.

How to proceed after this?

Thanks



SSA said:
Just publish the form programmatically and everything in the form will
automatically be submitted. You may use the following code to submit:

public void FormEvents_Submit(object sender, SubmitEventArgs e)
{

FileSubmitConnection fc =
(FileSubmitConnection)this.DataConnections["Main submit"];
// Modify the URL we want to submit to by concatenating the
string dLocation = this.Location.ToString();
fc.FolderUrl = dLocation.Substring(0, dLocation.LastIndexOf("/"));

// Execute the submit connection
try
{

fc.Execute();

e.CancelableArgs.Cancel = false;

}

catch (Exception ex)
{

e.CancelableArgs.Cancel = true;
}

Location is a local variable. You can skip it and use the following line
instead:

string dLocation = "http://server/dolib/forms/AllItems.aspx"; --> This is
just a sample, use the exact complete library URL here and you can also
capture the url programmatically. For example,

dLocation = this.Template.Uri.ToString();

Hope this helps

SSA
MOSS MVP
sadhana said:
Hi,
Is it possible to publish an InfoPath's data programmatically?
My task is that, I have some checkboxes and corresponding file
attachments(infopaths). when a user selects a checkbox and clicks on a
button, that file attachement (infopath) should be published to sharepoint
server document library.
Can we do it programmatically?

Thanks in advance
Sadhana
 

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