Tuesday, August 30, 2016

Using c# if debug

If you want to hide some of your code for production you can use the #if the statements. This allows you to do testing and not affect your production code. See the example below for more information.

#if Debug

//Code goes in this spot

#endif

Using system.collections.specialized.stringcollection in application settings

So, I'm in the application settings and want to put in a setting saved as type system.collections.specialized.strincollection. I started putting in a value and the message c#  cannot be converted to an instance of type system.collections.specialized.stringcollection pops up. What? So, started looking online as to how to enter the value.

Long story short, if you look to the end of the line, there is an "ellipses" button. Click on the button and it will allow you to enter the values and it will format everything for you.

Verifying Data For Text Files from vendors

So, I'm gathering feeds from a vendor. It's turning into be a pain in the ass. Here is what I gathered to make it easier the next time. I tried on numerous occasions to send documents with Data specifications. What I found out was they were not reading the specifications. And were just relying on me to review the data that was coming to us. So then I started to debug based on what data was sent. This initial process of course was more time-consuming on my part. But once I figured out what they were doing it's went faster. The good thing is that all the data specifications created can use internally on my end.

  1. Find out all of the fields available.
  2. Determine the initial set of fields needed.
  3. Have them start sending the feeds.
  4. Evaluate the file sense. Considering this set of feeds has headers I copied the header and example data.
  5. I took that header and example data and showed them a before and after of what the data should look like.
  6. Continue steps four and five until this is complete.

Friday, August 26, 2016

Excel The Formula is showing instead of the value

Format the cell to "General" then hit F2. The issue is that somewhere it was changed to text.

TF84013: you cannot modify a field that is read-only or a work item that restricts updates to valid users based on current conditions

Ran into this. Spreadsheet was still connected to  TFS. I ended up just copying the contents of the spreadsheet into brand-new Excel spreadsheet.

How do I combine text in excel sheet to create a sql statement or combine first and last name?

There are two ways to do this... you can use the shortcut or the more formal way:

  • shortcut: =("beginning" & "before column value" & B2 & "after column value and end")
  • formal: =Concatenate("beginning" & "before column value" & B2 & "after column value and end")

  1. Choose the cell where you want to combine the values.
  2. Type in:
    1.  =( 
    2. or 
    3. =Concatenate(
  3. Type in the starting text surrounded by quotes "me" or choose a cell that contains the first text you want to combine like first name.
  4. Type &” “& (a space enclosed in quotation marks).
  5. Type in the next set of text surrounded by quotes "me" or click the next cell with the text that you want to combine like last name.
One other thing I ended up using was the Substitute command as well. It allowed me to replace semicolons with commas for comma delimited exports.

Thursday, August 25, 2016

How to remove the date and author of a post in the Affinity Theme

Ok, this one took me a while...


  1. Log in as Admin to the WordPress site
  2. Navigate to Appearance | Editor
  3. Click on template-tags.php in the right hand navigation with all of the pages.
  4. Search for the following line:
    1. echo '' . $posted_on . ''; // WPCS: XSS OK
  5. If you don't want the date and the author to show, change this line to the following:
    1. //echo '' . $posted_on . ''; // WPCS: XSS OK
  6. If you don't want to only show the date, change this line to the following:
    1. echo '' . $posted_on . ''; // WPCS: XSS OK
  7. If you don't want only show the author, change this line to the following:
    1. echo ''; // WPCS: XSS OK

C# moving a file from one directory to another

C# moving a file from one directory to another


var fileName = @"xyz.txt";
var fromPath = @"c:\test\";
var toPath = @"c:\test\complete\";



public static void MoveFileToDirectory(string moveFile)
        {
            string fileOrigin = fromPath + moveFile;
            string fileDestination = toPath + moveFile;
            File.Move(fileOrigin, fileDestination);

        }

MoveFileToDirectory(fileName);

C# convert string YYYYMMDD string to datetime

Use DateTime.TryParseExact.
var newDate = DateTime.ParseExact("20160823""yyyyMMdd"CultureInfo.InvariantCulture);

Add if not already referenced
using System.Globalization;

Visual Studio 2010 Save a text file as a bat or cmd file without errors



Repost from...http://stackoverflow.com/questions/854360/visual-studio-inserts-invalid-characters-in-batch-files

In VS2008, select your file in the solution explorer and choose File...Save myfile.bat As...
On the down arrow on the Save button, choose Save with Encoding.
When saving in the Advanced Save Options dialog, Choose US-ASCII in the Encoding drop-down list. Set the line endings as required, or leave it as Current Setting.

Microsoft Windows 10 Pro How to put my programs, applications on top of each other.

Comparing data from a spreadsheet and SQL Server management studio. I wanted to compare the data and it was difficult switching between two screens on a laptop. So, I looked into a solution that could stack both windows on top of each other. The end result was I minimized all of my applications. Then I opened up these two applications. Then I right clicked on the Windows task bar, and chose "Show Windows Stacked". That was it.

The model backing the 'DataContext' context has changed since the database was created. Consider using Code First Migrations to update the database





I ran into this error message:
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration Electra1' again.

After a lot of researching and troubleshooting updating tables and updating values, I realized what the issue was. What I had done was update the Entity framework prior to running a new migration from another developer. I never actually updated the database though. So when I ran the migration from another developer, I received the above error message. To fix this, I ended up migrating my changes, and updated my database. So the real issue was I had to run my migration, and update the database.

The following link was the most beneficial after all of the research.
https://msdn.microsoft.com/en-us/data/jj591621.aspx

Wednesday, August 24, 2016

Import csv file with varbinary(max) using SQL Server Management Studio

So, I was never able to figure out how to import the varbinary(max) with the SQL Server Management Studio. I ended up using SSMS to create an import query, then updated the query. A pain, but it worked.

I found out the issue was, I was using SQL Server management studio and created a select query. Once I had the results I copied the table into a CSV file. The issue was the information copied over into text. When I tried to import this information, it translated the information as varbinary which resulted in a different result. I ended up dropping this technique. I later tried to import this data from a duplicate database which resolve my problem.

Found this... wasn't sure if it would help someone else.
I did see later on that switching the file type to windows-1251 will work.