C# (pronounced "C-sharp") is an object-oriented programming language from Microsoft that aims to combine the computing power of C++ with the programming ease of Visual Basic. C# is based on C++ and contains features similar to those of Java.
Question:How to insert data into sitecore forms programmatically through c# code with custom MVC form ?
Description:I need to insert form data into sitecore experience forms with sitecore 9 and above. I need to create completely custom mvc form and yet insert its data into sitecore forms module.
Posted by: Junaid Aziz | Posted on: Mar 30, 2023
Question:"Telerik.Sitefinity.Security.SecurityDemandFailException" exception while trying to create and upload the document to sitefinity's document library
Description:I am getting following exception while trying to upload document to sitefinity's document library Telerik.Sitefinity.Security.SecurityDemandFailException Telerik.Sitefinity.Libraries.Model.DocumentLibrary, Telerik.Sitefinity.Model was not granted ManageDocument in Document for principals with IDs 00000000-0000-0000-0000-000000000000 [Image] I am using following method and it is throwing exception while I am trying to set its parent library as seen in the above screenshot public static void CreateDocumentNativeAPI(Guid masterDocumentId, string parentDocumentLibraryUrlName, string documentTitle, Stream documentStream, string documentFileName, string documentExtension) { LibrariesManager librariesManager = LibrariesManager.GetManager(); Document document = librariesManager.GetDocuments().Where(d => d.Id == masterDocumentId).FirstOrDefault(); if (document == null) { //The document is created as master. The masterDocumentId is assigned to the master version. document = librariesManager.CreateDocument(masterDocumentId); //Set the parent document library. DocumentLibrary documentLibrary = librariesManager.GetDocumentLibraries().Where(d => d.UrlName.ToLower() == parentDocumentLibraryUrlName).SingleOrDefault(); document.Parent = documentLibrary; //Set the properties of the document. document.Title = documentTitle; document.DateCreated = DateTime.UtcNow; document.PublicationDate = DateTime.UtcNow; document.LastModified = DateTime.UtcNow; document.UrlName = Regex.Replace(documentTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); document.MediaFileUrlName = Regex.Replace(documentFileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); //Recompiles and validates the url of the document. librariesManager.RecompileAndValidateUrls(document); //Upload the document file. librariesManager.Upload(document, documentStream, documentExtension); //Save the changes. librariesManager.SaveChanges(); //Publish the DocumentLibraries item. The live version acquires new ID. var bag = new Dictionary<string, string>(); bag.Add("ContentType", typeof(Document).FullName); WorkflowManager.MessageWorkflow(masterDocumentId, typeof(Document), null, "Publish", false, bag); } }
Posted by: Khalid Abbas | Posted on: Jan 25, 2023
Question:Display Gregorian calendar date with Arabic digits instead of Hijri Calendar date in c#?
Description:we have a multilingual website in which we have event start date and end date which is correctly displayed for English language version of the page but when we go to its Arabic version of the page, it basically convert the date to Hijri calendar date. Currently we are using following code in which we are just getting the dates from database and format it as shown string startDate= sourceEvent?.Fields.EventStart.ToString("dd.MM.yy"); string endDate= sourceEvent?.Fields.EventEnd.ToString("dd.MM.yy"); Output for English page 25.05.22 - 28.05.22 Output of Arabic page: 24.10.43 - 27.10.43 instead the Arabic page output we required: ۲۵.۰۵.۲۲ - ۲۸.۰۵.۲۲
Posted by: Umer khan | Posted on: May 30, 2022
Question:Getting 415 "Unsupported Media Type" on post request from reactjs to asp.net core apicontroller ?
Description:I am getting 415 "Unsupported Media Type" on a post request, my reactjs submit method looks like the following one where I am sending data using FormData handleEmployeeSubmit(employee) { const data = new FormData(); data.append('FirstName', employee.firstName); data.append('MiddleName', employee.middleName); data.append('LastName', employee.lastName); data.append('Designation', employee.designation); data.append('Salary', Number(employee.salary)); const xhr = new XMLHttpRequest(); xhr.open('post', this.props.submitUrl, true); xhr.onload = () => this.loadEmployeesFromServer(); xhr.send(data); } and my APIController method look like the following one [HttpPost] [Route("Create")] public async Task<ActionResult> create([FromBody] Employee employee) { int empid = await _employeerepository.Create(employee); return Ok(empid); } any help will be appreciated as I am new to both reactjs and .net core
Posted by: Emerging Expert | Posted on: May 13, 2022
Question:how to resolve "cannot convert from int? to int" in c#, compile time error?
Description:I have my controller method taking input parameter int? And one of my inner method taking int as input parameter so I basically wanted to know how to convert int?(Nullable int) to int in C#.
Posted by: Umer khan | Posted on: Apr 29, 2022
Question:Difference between Abstract Class, Static Class and Sealed Class in C#?
Description:Need to get more clarity on each one (Abstract Class, Static Class and Sealed Class) of them so that I can identify when to use which one and why
Posted by: Samantha Jones | Posted on: Mar 24, 2022
Question:how to increase default session timeout for asp.net mvc site using web.config?
Description:Currently my site’s session expires a bit quickly while my site contains some huge forms for users to fill out so I wanted to increase the session timeout for the users to get enough time.
Posted by: Khalid Abbas | Posted on: Mar 18, 2022
Question:remove server information from response header using web.config in different versions of IIS?
Description:I have different sites hosted on multiple environments one is using IIS 8 and the other one is using IIS 10 , I wanted to remove the server information from the response header using web.config and currently I am using following URL Rewrite Outbound rule but unfortunately it is not working in any of the environment. <rewrite> <outboundRules rewriteBeforeCache="true"> <rule name="Remove Server header"> <match serverVariable="RESPONSE_Server" pattern=".+" /> <action type="Rewrite" value="" /> </rule> </outboundRules> </rewrite>
Posted by: Khalid Abbas | Posted on: Mar 17, 2022
Question:NuGet Package restore failed/build failed for my project on new visual studio instance
Description:I have just installed the latest visual studio 2019 (Community Edition) , just pull my project on a new machine which is working fine on another machine but now I am getting following error on some of the nuget packages.(I have checked that these packages are not downloaded) Severity Code Description Project File Line Suppression State Error This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105
Posted by: Khalid Abbas | Posted on: Jun 15, 2021
Question:How to get the time difference between utc time and local time in C#?
Description:I have .net base website which currently have server time zone set to GMT+5, I need to extract that 5 from it dynamically so that once I change the time zone of the server or deploy the same site on another sever with different time zone, I should be able to extract that time difference in that case.
Posted by: Umer khan | Posted on: Sep 11, 2020