Domanda

I create a folder when run a workflow, I want to use "Repository" field from current item, like a paramenter (this is a location when I want to create the folder), when assign to variable respository a static link "https: //site/teamSite/" works, but in this case fail.

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
    {
        int item = onWorkflowActivated1.WorkflowProperties.ItemId;          

        SPFieldUrlValue fieldValue = new SPFieldUrlValue(SPContext.Current.Item["Repository"].ToString());
        string linkTitle = fieldValue.Description;
        string linkUrl = fieldValue.Url;          

        string repository = linkUrl;
        string ruta = "Shared Documents/Folder"+item;
        //string respository  = "https: //site/teamSite/"
        using (SPSite site = new SPSite(repository))           
        {
            using (SPWeb web = site.OpenWeb())
            {
                web.Folders.Add(ruta);
                workflowProperties.Item["Folder"] = repository+ruta;                   
                workflowProperties.Item.Update();  
            }
        }

    }
È stato utile?

Soluzione

 private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
    {
        //Currente item
        int item = onWorkflowActivated1.WorkflowProperties.ItemId;
        SPItem current =  onWorkflowActivated1.WorkflowProperties.Item;    
        //Get url from field
        SPFieldUrlValue fieldValue = new SPFieldUrlValue(current["Repository"].ToString());
        string linkTitle = fieldValue.Description;
        string linkUrl = fieldValue.Url;            
        string ruta = "Shared Documents/Folder"+item;

        using (SPSite site = new SPSite(linkUrl))
        {
            using (SPWeb web = site.OpenWeb())
            {
                web.Folders.Add(ruta);
                workflowProperties.Item["Folder"] = linkUrl + ruta;                   
                workflowProperties.Item.Update();  
            }
        }

    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top