Category: Work

Giving write permissions through Remote Registry

By , April 28, 2011 11:50 am

So, today I had to give a user permission to access the Remote Registry on Windows Server 2008 R2 machine. You could be forgiven for thinking this would be a relatively trivial task.

Some quick googling revealed that before a user can even read anything, they must have permissions on the following key:

HKLM\SYSTEM\CurrentControlSet\Control\SecurePipeServers\winreg

Granting the user Read permission (or Full Control) on this key, enables them to connect to the remote registry and browse it. This is where the useful information stops, but it turns out in order to give the user permission to write to the registry you need to manually set their permission on every key they want to write to.

To be fair this is quite logical, it’d just be nice if it was documented somewhere :)

Access is Denied Exception when writing to Spreadsheet from ASP.Net

By , September 16, 2009 5:48 pm

I recently got the following error message whilst trying to write to an excel file using the openXML library in ASP.Net and C#:

System.ApplicationException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.IO.IsolatedStorage.IsolatedStorageFile.nGetRootDir(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.InitGlobalsNonRoamingUser(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetRootDir(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetGlobalFileIOPerm(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.Init(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
at MS.Internal.IO.Packaging.PackagingUtilities.ReliableIsolatedStorageFileFolder..ctor()
at MS.Internal.IO.Packaging.PackagingUtilities.GetDefaultIsolatedStorageFile()
at MS.Internal.IO.Packaging.PackagingUtilities.CreateUserScopedIsolatedStorageFileStreamWithRandomName(Int32 retryCount, String& fileName)
at MS.Internal.IO.Packaging.SparseMemoryStream.EnsureIsolatedStoreStream()
at MS.Internal.IO.Packaging.SparseMemoryStream.SwitchModeIfNecessary()
at MS.Internal.IO.Packaging.CompressEmulationStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at MS.Internal.IO.Packaging.CompressStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(String value)
at System.Xml.XmlTextEncoder.Write(String text)
at System.Xml.XmlTextWriter.WriteString(String text)
at System.Xml.XmlAttribute.WriteContentTo(XmlWriter w)
at System.Xml.XmlAttribute.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlDocument.WriteContentTo(XmlWriter xw)
at System.Xml.XmlDocument.Save(Stream outStream)
at OfficeOpenXml.ExcelWorksheet.Save()
at OfficeOpenXml.ExcelWorkbook.Save()
at xxx.addDataSetToExcel(DataSet DataSetSource, String fileName, String title, String subject, String category, String comments, String fileType)

Turns out that this is in no way a common problem (google was not my friend on this occasion). After nearly an entire day trying to figure this one out I finally came accross the solution and intend to share it here:

The openXML library uses a MemoryStream object when creating the spreadsheet – When the amount of data your putting into your spreadsheet gets too large to be held in memory, it starts to offload the data to disk. This is where the problem arises.

For whatever reason, ASP.NET decides it’s going to try to put the data into an obscure directory that doesn’t always exist – C:\Documents and Settings\Default User\Local Settings\Application Data\IsolatedStorage. I’m not entirely sure why it comes up with Access is Denied, presumabley because the user in the application pool doesn’t have permission to create a directory?

In any case, if you get this problem, just create the above directory and make sure that the user in your application pool (or Everyone) has read and write access to it.

Excel – Update formulas on Open

By , April 29, 2009 10:16 am

Most of the time this is a relatively trivial exercise. In the majority of cases, simply setting ‘Workbook Calculation’ to ‘Automatic’ in the Excel options will give the desired effect.

However, I recently stumbled across a situation where this doesn’t work. If you find yourself entering data into an Excel workbook through some other means – in my case, using the OpenXML libraries in C# – then you may need to force excel to update any formulas you had.

The solution is simple, using a small VB macro. To get it to happen when the workbook is opened, use the following code:

Private Sub Workbook_Open()
 
 Application.CalculateFullRebuild
 
End Sub

If you put that in the code for the main workbook (as opposed to one of the sheets) then it should happen when the spraedsheet is opened.

Transact-SQL – Auto Increment Primary Key

By , January 12, 2009 3:06 pm

If like me you learnt SQL using MySQL, and then gone into a job and found yourself using Microsoft’s SQL Server, you’ll probably be as irritated as me to find that Transact-SQL does not feature the ‘AUTO INCREMENT’ keyword that MySQL provides. Fortunately, the solution is far easier here than it is in PostgreSQL.

All you need is to add IDENTITY(1,1) in your column definition. I’m not going to pretend to understand exactly what this does, only that it will Automatically increment and ID field for you. If anyone wants to enlighten me on exactly what it does, then feel free :)

An Example is below:

   1: CREATE TABLE dbo.myTable(
   2:     ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
   3:     ColumnA VARCHAR(200),
   4:     ColumnB BIT
   5: )
   6:  

Page Refresh Animations in ASP.NET

By , December 19, 2008 11:33 am

Page Refresh Animations

This refers to the way in which we can display some form of feedback to the user that the page is being updated, without the need for an ugly page flash or the page seemingly doing nothing.

 As always there are several ways to achieve this – a quick google will probably reveal several. Below is probably the most reliable method for our usages.

Continue reading 'Page Refresh Animations in ASP.NET'»

Visual Studio 2008 Settings

By , November 12, 2008 6:57 pm

Right, I recently discovered some nice looking colour themes for Visual Studio 2008.

So, i’ve decided to share. I can’t be bothered to put a screen shot up, so if you want to see it you’ll just have to try it. Basically, it’s a dark colour scheme. Dark blue background, and brightly coloured text (but not so much so that it blinds you!). Anyway, point is i like to use it and i’m sharing.

VS2008 Colour Scheme VS2008 Colours and Editor Settings

There are two files – one of them contains my Text Editor settings as well as the Colour Scheme settings. The other is just the colour scheme. Enjoy.

The ASP.NET ViewState…

By , November 6, 2008 3:42 pm

The ViewState in ASP.Net is one of those weird and wonderful things that Microsoft obviously thought was a good idea at the time. Granted, it is quite useful but as with all things like that, it comes with a price – and a fairly hefty one at that if not used sensibly. Continue reading 'The ASP.NET ViewState…'»

Writing Date to Excel from ASP.NET and C#

By , October 31, 2008 11:49 am

Ok, so i’ve just been working on outputting data from an ASP.NET based web app into an Excel Spreadsheet. I’m not going to go into the details of how to do that, but only how to avoid one little problem i encountered.
Continue reading 'Writing Date to Excel from ASP.NET and C#'»

Panorama Theme by Themocracy