Thanks for your replies . I got some workarounds from it and built my solution.
Workaround
Add a attachment control in the InfoPath form. I had a submit button which submits the document in a specified document library and returns a link from it which gets added up in a textbox in the InfoPath form . In the design mode the textbox is changed to hyperlink. When it form is deployed we can see the textbox is viewed as a hyperlink.
Bits of code to detach the file, place it in document library , get a link value to the hyperlink converted textbox.
char[] charFileName = System.Text.UnicodeEncoding.Unicode.GetChars(fnBytes);string fileName = new string(charFileName);
fileName = fileName.Substring(0, fileName.Length - 1);
// The file is located after the header, which is 24 bytes long
// plus the length of the filename. byte[] fileContents = new byte[attachmentNodeBytes.Length - (24 + fnLength)];for (int i = 0; i < fileContents.Length; ++i)
{
fileContents[i] = attachmentNodeBytes[24 + fnLength + i];
}
string SiteAttachURL = _strDocLibURL + strReqID + "_" + fileName;
Add it to document library
SPSite siteCol = null;
SPWeb curSite = null;siteCol = new SPSite("url of root site);
curSite = siteCol.OpenWeb();
curSite.AllowUnsafeUpdates = true;
curSite.Files.Add(SiteAttachURL, fileContents);
Add link in the hyperlink converted textbox
XPathNavigator nav1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:secContentView/my:secContent/my:secAttachments/my:templateURL", NamespaceManager);
nav1.SetValue(SiteAttachURL);
Code to Detach document from the InfoPath attachment control can be follwed from the below link
http://www.sharepointblogs.com/ssa/archive/2008/01/15/infopath-delete-file-attachments-programmatically-c.aspx
Please check whether you have appropriate permissions to add a document to the document library and add AllowUnsafeUpdates = true;