Search code examples
c#formsvisual-studio-2012sharepointinfopath2010

How to generate a name with unique ID from infoPath form to Sharepoint Library? C#


I have made a submit button with c# code that submits from infopath form to SharePoint library. In infopath form I have a field and you have to type name. Name must be always the same john How can i make after name to generate a unique number for each name that is typed I.E, I add a name as following: john the code should generate an ID, finally name will be added as john 001,john 002, john 003 etc. My infopath form: enter image description here

My code for submit in c#:

XPathNavigator root = MainDataSource.CreateNavigator();

// Generate a name for the form to be saved in SharePoint
string formName =  Guid.NewGuid().ToString();

// Set the name of the form on the data connection
root.SelectSingleNode(
   "//my:formName ", NamespaceManager).SetValue(formName);

// Submit the form to SharePoint
DataConnection spConn =
DataConnections["SharePoint Library Submit"];
spConn.Execute();
 e.CancelableArgs.Cancel = false;

How can i do that


Solution

  • string formName = "Kerkesa" + random(); i was looking for this

    And on the random() function there is a GUID GENERATOR