DocuSignAPI: Optional Custom Text Tab with value can't be modified - c#

I am trying to create a tab via the DocuSign API with the following requirements:
Optional
Text
Anchored
Shared
Has a Default Value
However, when i set the value of the tab before composing and sending the envelope, the tab will not be editable to any of the Recipients. See code below:
private static Tab buildOptionalInputTab(String recId, String docId, String defaultValue)
{
Tab tab = new Tab();
tab.RecipientID = recId;
tab.AnchorTabItem = new AnchorTab { AnchorTabString = "Tracking #:" };
tab.AnchorTabItem.XOffset = 135;
tab.AnchorTabItem.YOffset = -8;
tab.DocumentID = docId;
tab.Type = TabTypeCode.Custom;
tab.CustomTabRequiredSpecified = true;
tab.CustomTabRequired = false;
tab.CustomTabType = CustomTabType.Text;
tab.Name = "Tracking #";
tab.SharedTabSpecified = true;
tab.SharedTab = true;
tab.Value = defaultValue; //REMOVE THIS LINE AND IT WORKS
return tab;
}

Add tab.Locked = false; to your SOAP request and you should be able to set the default value while also making it editable.

Related

Setting Excel worksheet protection with EPPlus

I'm trying to set worksheet permissions for an XLSM file using EPPlus but it seems I can only set the default protection level, individual protections are not being set. For the record, I'm trying to accomplish programmatically method 1 in this article. Here's the code I'm using:
using (var p = new ExcelPackage("output.xlsm"))
{
var ws = p.Workbook.Worksheets["MySheet"];
// Set some cell values here
// Filtering, sorting, protection
ws.Cells[7, 1, 10, 5].AutoFilter = true;
ws.View.FreezePanes(7, 1);
ws.ProtectedRanges.Add("FilteredCells", new ExcelAddress(7, 1, 10, 5));
// Worksheet protection
ws.Protection.AllowAutoFilter = true;
ws.Protection.AllowDeleteColumns = false;
ws.Protection.AllowDeleteRows = false;
ws.Protection.AllowEditObject = false;
ws.Protection.AllowEditScenarios = false;
ws.Protection.AllowFormatCells = false;
ws.Protection.AllowFormatColumns = false;
ws.Protection.AllowFormatRows = false;
ws.Protection.AllowInsertColumns = false;
ws.Protection.AllowInsertHyperlinks = false;
ws.Protection.AllowInsertRows = false;
ws.Protection.AllowPivotTables = false;
ws.Protection.AllowSelectLockedCells = false;
ws.Protection.AllowSelectUnlockedCells = true;
ws.Protection.AllowSort = true;
ws.Protection.IsProtected = true;
ws.Protection.SetPassword("hunter2");
p.SaveAs(new FileInfo("output.xlsm"));
}
This runs without errors, but when I open the file in Excel, or load it back into EPPlus, I find that different protection options have been applied:
AllowAutoFilter = false
AllowDeleteColumns = false
AllowDeleteRows = false
AllowEditObject = true
AllowEditScenarios = true
AllowFormatCells = false
AllowFormatColumns = false
AllowFormatRows = false
AllowInsertColumns = false
AllowInsertHyperlinks = false
AllowInsertRows = false
AllowPivotTables = false
AllowSelectLockedCells = true
AllowSelectUnlockedCells = true
AllowSort = false
IsProtected = true
These obviously aren't the permissions I set before, so how can I make sure they are set correctly? Everything else is saved correctly.
Here is the source:
https://github.com/pruiz/EPPlus/blob/master/EPPlus/ExcelSheetProtection.cs
Setting the IsProtected property is overwriting your choices:
public bool IsProtected
{
get
{
return GetXmlNodeBool(_isProtectedPath, false);
}
set
{
SetXmlNodeBool(_isProtectedPath, value, false);
if (value)
{
AllowEditObject = true;
AllowEditScenarios = true;
}
else
{
DeleteAllNode(_isProtectedPath); //delete the whole sheetprotection node
}
}
}
Move your IsProtected = true call to the start of the code or handle however you want, but you are accidently overriding your previous choice. I would look at the properties at that link to see which ones are going to override your existing selections.

DevExpress MVC Editors get value on Controller

I have a popupcontrol declared in my razor cshtml file as follow:
#Html.DevExpress().PopupControl(settings =>
{
settings.Name = "popSendBackReview";
settings.HeaderText = "Send Review Back to Scheduler";
settings.AllowResize = false;
settings.ShowHeader = true;
settings.ShowOnPageLoad = false;
settings.AllowDragging = true;
settings.CloseAction = CloseAction.CloseButton;
settings.CloseOnEscape = false;
settings.Modal = true;
settings.PopupElementID = "popSendBackReview";
settings.AutoUpdatePosition = true;
settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
settings.Height = 280;
settings.Width = 450;
settings.SetContent(() =>
{
Html.RenderPartial("_SendBackReviewPanel");
});
}).GetHtml()
The partial view contains a memo box and button that calls an action:
#Html.DevExpress().Memo(settings =>
{
settings.Width = 300;
settings.Height = 150;
settings.Style.Add("margin-bottom", "10px");
settings.Name = "txtReviewComment";
settings.Properties.ValidationSettings.RequiredField.IsRequired = true;
settings.Properties.ValidationSettings.RequiredField.ErrorText = "A Review Comment is Required.";
settings.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.Text;
settings.Properties.ValidationSettings.ErrorTextPosition = ErrorTextPosition.Bottom;
settings.Properties.ValidationSettings.Display = Display.Dynamic;
settings.Properties.ValidationSettings.ValidationGroup = "Review";
}).GetHtml()
#Html.DevExpress().Button(settings =>
{
settings.Name = "btnSaveReview";
settings.Text = "Send Back for Scheduler Review";
settings.UseSubmitBehavior = false;
settings.ValidationGroup = "Review";
settings.RouteValues = new { Controller = "Matter", Action = "ResolveReview", Pass = false, Comment = Model.CommentText };
}).GetHtml()
#Html.DevExpress().Button(settings =>
{
settings.Name = "btnCancelReview";
settings.Text = "Cancel";
settings.UseSubmitBehavior = false;
settings.ClientSideEvents.Click = "function(s,e) { popSendBackReview.Hide(); }";
}).GetHtml()
I am trying to get the text that is typed into this box on the server side (in the action on my controller). In other places in my application I have been able to use the following code to get values of controls:
public ActionResult ResolveReview(bool Pass)
{ ...
EditorExtension.GetValue<string>("txtReviewComment")
...}
However this returns null in this scenario. What is the correct way to get this value from a control in a partial view rendered in a popupcontrol?
In general, it is necessary to wrap editors within a form container in order to pass the entire form's content on submit. Then, it is possible to retrive the required editor's value using the standard Model Binding mechanism. When using DevExpress MVC Editors, make sure that the DevExpressEditorsBinder is registered:
#using(Html.BeginForm("ResolveReview")) {
#Html.DevExpress().Memo(settings => {
settings.Name = "txtReviewComment";
}).GetHtml()
#Html.DevExpress().Button(settings => {
settings.Name = "btnSaveReview";
settings.UseSubmitBehavior = true;
}).GetHtml()
}
public ActionResult ResolveReview(bool Pass) {
EditorExtension.GetValue<string>("txtReviewComment")
}
or
public ActionResult ResolveReview(string txtReviewComment) { ... }
Check the MVC Data Editors - Model Binding and Editing learning resource.
I found the answer on my own, my button was causing a GET method to fire instead of POST. By setting "UseSubmitBehavior" to true on my save button, it started firing the POST function and allowing the
EditorExtension.GetValue<string>("txtReviewComment")
line to get a value.

Displaying image in web application

i have problem with displaying image in my web app. It took photo from database, and should dispay in web app.
protected void btnShowPhoto_Click(object sender, EventArgs e)
{
string adresURL = #"~/Content";
string camPath = "";
string[] tab = new string[10];
CheckBox[] _boxes = new CheckBox[] { this.CheckBox1, this.CheckBox2, this.CheckBox3, this.CheckBox4, this.CheckBox5, this.CheckBox6, this.CheckBox7, this.CheckBox8 };
System.Web.UI.WebControls.Image[] _images = new System.Web.UI.WebControls.Image[] { this.Image1, this.Image2, this.Image3, this.Image4, this.Image5, this.Image6, this.Image7, this.Image8 };
Label[] _labels = new Label[] { this.lblCameraName1, this.lblCameraName2, this.lblCameraName3, this.lblCameraName4, this.lblCameraName5, this.lblCameraName6, this.lblCameraName7, this.lblCameraName8 };
System.Web.UI.HtmlControls.HtmlAnchor[] _linkscontrol = new System.Web.UI.HtmlControls.HtmlAnchor[] { this.imagelink1, this.imagelink2, this.imagelink3, this.imagelink4, this.imagelink5, this.imagelink6, this.imagelink7, this.imagelink8 };
for (int i = 0; i < 8; i++)
{
_images[i].Visible = false;
_labels[i].Visible = false;
_linkscontrol[i].HRef = "";
}
for (int i = 0; i < 8; i++)
{
if (_boxes[i].Checked)
{
camPath = null;
tab = null;
camPath = this.GridView2.Rows[i].Cells[0].Text;
tab = camPath.Split(new string[] { "StoredPhotos" }, StringSplitOptions.None);
//Virtual Path'a
camPath = adresURL + tab[1].Replace(#"\", "/");
_labels[i].Visible = true;
_labels[i].Text = this.GridView2.Rows[i].Cells[1].Text;
_linkscontrol[i].HRef = camPath;
_images[i].ImageUrl = camPath;
_images[i].Visible = true;
}
else
_images[i].Visible = false;
}
}
I have problem with my virtual path probably. CamPath(Virtual Path) becomes from : E:\Photo\StoredPhotos\20151010\000003819619_201512021335_1_C1, and finally looks: ~/20151010/000003819619_201512021335_1_C1
This path means nothing to a web browser:
~/20151010/000003819619_201512021335_1_C1
It doesn't know what to do with that ~ directory. That's a server-side concept, not a client-side concept. So your server-side code needs to resolve that to an actual path.
It could be as simple as just explicitly starting from the root of the server:
string adresURL = #"/Content";
So the resulting URL would start with /Content/..... and the browser would check for the image in that path.
But if the application isn't (or might not be) the root of the server domain then you'd need to either manually account for that or use a server-side helper of some sort. There are a variety of ways to go about that, for example:
_images[i].ImageUrl = System.Web.VirtualPathUtility.ToAbsolute(camPath);
The browser expect access to image via http protocol, if you want view the image you have 2 diffrerent way:
(simple) Create a virtual directory under iis that point to a phisical folder E:\Photo\StoredPhotos\ and called StoredPhotos, in _images[i].ImageUrl you may set the value /StoredPhotos/20151010/000003819619_201512021335_1_C1.jpg
(complex) Build a class that read the file on the disk and write it to the response (use IHttpHandler interface), add this handler to web.config and set _images[i].ImageUrl the value of 'NameOfHandler.aspx?20151010/000003819619_201512021335_1_C1

Creating User in dotnetnuke and Assign Role using c#

I'm trying to create a user programatically using C# in dnn. When ever I execute the code below, it throws object reference error. I tried breaking the code and I found out that its not getting inside the if (result == UserCreateStatus.Success) statement. Whenever I point my mouse to the result instant, it shows an invalid password message. The thing is that I have used this same code before somewhere else and its working fine. I even copied what I used earlier on but its keeps showing the same error. Please is there anything I'm missing?
//Generating 8 char passwor
Random adomRng = new Random();
string rndString = string.Empty;
char c;
for (int i = 0; i < 8; i++)
{
while (!Regex.IsMatch((c = Convert.ToChar(adomRng.Next(48, 128))).ToString(), "[A-Za-z0-9]")) ;
rndString += c;
}
string space = " ";
UserInfo oUser = new UserInfo();
oUser.PortalID = this.PortalId;
oUser.IsSuperUser = false;
oUser.FirstName = Session["fname"].ToString();
oUser.LastName = Session["lname"].ToString();
oUser.Email = Session["email"].ToString();
oUser.Username = Session["username"].ToString();
oUser.DisplayName = Session["fname"].ToString() + space.ToString() + Session["lname"].ToString();
//Fill MINIMUM Profile Items (KEY PIECE)
oUser.Profile.PreferredLocale = PortalSettings.DefaultLanguage;
//oUser.Profile.PreferredTimeZone =PortalSettings.TimeZoneOffset;
oUser.Profile.FirstName = oUser.FirstName;
oUser.Profile.LastName = oUser.LastName;
//Set Membership 17:
UserMembership oNewMembership = new UserMembership();
oNewMembership.Approved = true;
oNewMembership.CreatedDate = System.DateTime.Now;
oNewMembership.Email = oUser.Email;
oNewMembership.IsOnLine = false;
oNewMembership.Username = oUser.Username;
oNewMembership.Password = rndString;
UserCreateStatus result = UserController.CreateUser(ref oUser);
if (result == UserCreateStatus.Success)
{
RoleController oDnnRoleController = new RoleController();
//Get the role information
RoleInfo oCurrentRole = oDnnRoleController.GetRoleByName(this.PortalId, Request.QueryString["TSORole"].ToString());
// RoleInfo oCurrentRole1 = oDnnRoleController.GetRoleByName(this.PortalId, " Subscribers");
//Assign to user
oDnnRoleController.AddUserRole(this.PortalId, oUser.UserID, oCurrentRole.RoleID, Null.NullDate, Null.NullDate);
// oDnnRoleController.DeleteUserRole(this.PortalId, int.Parse(oUser.UserID.ToString()), oCurrentRole.RoleID);
}
The reason why same code works for one and not the other could be different password rules for these websites. Make sure you are generating a password that complies with the password requirements of the target website.

I am getting An Error with c# and Docusign How Do i resolve this error

I am getting the error
Unable to load template. Unable to load template from TemplateReference(0). Error: Data at the root level is invalid. Line 1, position 1.
below is a simplified version of the code i am using...
If i don't use the template reference type of the code everything works fine. But when i start using a template reference.. Nothing works and i get this error. Anyone have a suggestion?
TemplateReference _tempRef = new TemplateReference();
TemplateReference[] _tempRefs = new TemplateReference[] { };
TemplateReferenceRoleAssignment[] _roleAssignmentArray = new TemplateReferenceRoleAssignment[] { };
Recipient[] _recipientsArray = new Recipient[] { };
EnvelopeInformation envelope = new EnvelopeInformation();
Recipient recipient = new Recipient();
recipient.ID = "1";
recipient.Email = "someemail#somewhere.com";
recipient.UserName = "Some Person";
recipient.Type = RecipientTypeCode.Signer;
recipient.RequireIDLookup = false;
Array.Resize(ref _roleAssignmentArray, 1);
Array.Resize(ref _recipientsArray, 1);
_recipientsArray[0] = recipient;
var saRoleAssignment = new TemplateReferenceRoleAssignment
{
RecipientID = "1",
RoleName = "SA"
};
_roleAssignmentArray[0] = saRoleAssignment;
var reference = new Docusign.TemplateReference();
reference.Template = "49C0BE2B-48F7-4F38-B44A-19EB8E6A1A38";
reference.Document = new Docusign.Document();
reference.Document.PDFBytes = new byte[0];
reference.Document.ID = Convert.ToString(1);
reference.Document.Name = "please work";
reference.RoleAssignments = _roleAssignmentArray;
Array.Resize(ref _tempRefs, 1);
_tempRefs[1 - 1] = reference;
//.NET
//.NET
envelope.AccountId = "accountID";
envelope.Subject = "Sample Application";
envelope.EmailBlurb = "You can add a personal message here.";
APIServiceSoapClient apiService = new APIServiceSoapClient();
apiService.ClientCredentials.UserName.UserName = "userhere";
apiService.ClientCredentials.UserName.Password = "pass";
var status = apiService.CreateEnvelopeFromTemplates(_tempRefs, _recipientsArray, envelope, true);
If you're using DocuSign's SOAP api instead of REST then you should definitely familiarize yourself with the SOAP SDK on GitHub:
https://github.com/docusign/DocuSign-eSignature-SDK
There's an MS.NET (C#) version which has sample code that works out of the box, you only need to enter your api credentials. I suggest you use that as your project base, especially since it was updated recently.
Since you have not identified which line the error is stemming from it's a little hard to debug, but if you look at SendTemplate.aspx.cs in the SDK you'll see that the template reference is instantiated like this:
// Construct the template reference
var templateReference = new DocuSignAPI.TemplateReference
{
TemplateLocation = DocuSignAPI.TemplateLocationCode.Server,
Template = TemplateTable.Value,
RoleAssignments = CreateFinalRoleAssignments(recipients)
};
where CreateFinalRoleAssignments() is defined as:
protected DocuSignAPI.TemplateReferenceRoleAssignment[] CreateFinalRoleAssignments(DocuSignAPI.Recipient[] recipients)
{
// Match up all the recipients to the roles on the template
return recipients.Select(recipient => new DocuSignAPI.TemplateReferenceRoleAssignment
{
RecipientID = recipient.ID, RoleName = recipient.RoleName
}).ToArray();
}

Categories

Resources