Thursday, March 22, 2012

How about an MVC file upload code sample?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using ApptSchedule.Models;

namespace ApptSchedEF.UsrControls
{


public partial class ucfileUpload : System.Web.UI.UserControl
{
private int usrId = 0;
public string Filename = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PopulateDropdownLists();
}
}

protected void PopulateDropdownLists()
{
ApptSchedEntities entities = new ApptSchedEntities();
ddLstCategories.DataSource = entities.FileCategories;
ddLstCategories.DataBind();

ddLstFileTypes.DataSource = entities.FileTypes;
ddLstFileTypes.DataBind();
}
protected void btnImageUpload_Click(object sender, EventArgs e)
{
usrId = SessionCache.VendorId;
string pathRel = "~/Content/uploads/" + DateTime.Today.Year + "/" + usrId.ToString() + "/";
string path = Server.MapPath(pathRel);

Filename = FileUploadImage.FileName;
if (FileUploadImage.HasFile)
try
{
if (!Directory.Exists(path))
{
DirectoryInfo di = Directory.CreateDirectory(path);
}

FileUploadImage.SaveAs(path + FileUploadImage.FileName);
lbMsg.Text = "File name: " +
FileUploadImage.PostedFile.FileName + "
" +
FileUploadImage.PostedFile.ContentLength + " kb
" +
"Content type: " +
FileUploadImage.PostedFile.ContentType;
lbMsg.CssClass = "fieldcaption";
UploadFile(usrId, pathRel);
}
catch (Exception ex)
{
lbMsg.Text = "ERROR: " + ex.Message.ToString();
lbMsg.CssClass = "alert";
}
else
{
lbMsg.Text = "You have not specified a file.";
lbMsg.CssClass = "alert";
}

}

protected int FileType(string fileContentType, int id)
{
if (fileContentType.ToLower().Contains("image"))
{ return 1; }
else if (fileContentType.Contains("pdf"))
{ return 2; }
else if (fileContentType.Contains("doc"))
{ return 3; }
else if ((fileContentType.Contains("xls")) || (fileContentType.Contains("csv")))
{ return 4; }
else if (fileContentType.Contains("txt"))
{ return 5; }
else return id;
}
protected void UploadFile(int vendId, string pathRel)
{
ApptSchedEntities entity = new ApptSchedEntities();
VendorUploads up = new VendorUploads();
up.vendorId = vendId;
up.fileCategoryId = Convert.ToInt32(ddLstCategories.SelectedValue);
up.fileTypeId = Convert.ToInt32( ddLstFileTypes.SelectedValue);
up.filename = FileUploadImage.FileName;
up.pathURL = pathRel + FileUploadImage.FileName;
up.Year = DateTime.Today.Year;
up.DateCreated = DateTime.Today;
up.DateUpdated = DateTime.Today;
up.fileContenttype = FileUploadImage.PostedFile.ContentType;

up.fileTypeId = FileType(up.fileContenttype.ToLower(),up.fileTypeId);
up.fileSize = FileUploadImage.PostedFile.ContentLength;

entity.VendorUploads.AddObject(up);
entity.SaveChanges();
if (up.fileContenttype.StartsWith("image") == true)
{
imgtnUploadedFile.ImageUrl = "~/Content/upload/"+ up.Year + "/" + up.vendorId + "/" + up.filename;
int kbs = Convert.ToInt32(up.fileSize) / 100;
imgtnUploadedFile.ToolTip = up.filename + " fileSize=" + kbs + "kb";
}

}
}
}

Tuesday, August 23, 2011

Manually Installing WordPress on Windows host at Arvixe vs Brinkster

I thought this was going to be hard, since one of my hosting sites, Arvixe.com, is not that user friendly. Nothing in the Arvixe knowledgebase in this topic.

Brinkster.com is my other hosting site, and it is much easier to use.
The chat session people are friendly and very American, and understand what I want, and are very helpful. Brinkster.com has in their knowledgebase how to install a WordPress site.

I surfed the web and found this great blog on:
How to manually install WordPress on a Windows host at Arvixe.
tech.jaressloo.com/June 2010

In a nutshell here are the steps:
  1. Download the latest version of WordPress from WordPress.org to your local computer.
  2. Open the index.php file, and change line 17 (or there abouts) :

    • It says that it’s Line 17 in your index.php file. If you look at line 17 in your
      index.php file in the root directory of your blog (not in the
      wp-admin) folder, you should see a call to wp-blog-header.php.
    • So, the natural thing to do is to change
      the index.php file on line 17 instead of saying “./wp-blog-header.php
      to change that to “wp-blog-header.php” (without the ./ in the
      begging). If you make that change, you’ll see that it works now! BUT
      only for the two themes provided in WordPress (as of 2010).

  3. When I tried it, it seemed to work for all the themes that I chose (August 2011)

  4. Read through the Word Press 5 minute install document.
  5. Login to Arvixe.
  6. Under the Database tab, select a MySQL database. WordPress works with MySQL (not SQL Server)
  7. Add a new MySQL database - give it a name (e.g. wpSQLdbBlogA)

  8. Add a username and password for this new MySQL database '

    wpSQLdbBlogA'


    (e.g. 'wpSQLdbUsername' and 'wpSQLdbPassword$')



  9. On your local machine, make a copy of this file: wp-config-sample.php
  10. Rename the copy: wp-config.php
  11. Open this file ,and scroll to this section at approx line 17:

    // ** MySQL settings - You can get this info from your web host ** //

    /** The name of the database for WordPress */
    define('DB_NAME', 'database_name_here');

    /** MySQL database username */
    define('DB_USER', 'username_here');

    /** MySQL database password */
    define('DB_PASSWORD', 'password_here');

    /** MySQL hostname */
    define('DB_HOST', 'localhost');


  12. Change 'database_name_here' to 'wpSQLdbBlogA' or whatever you named your MySQL database.
  13. Change 'username_here' to your Arvixe MySQL database username (e.g 'wpSQLdbUsername'
  14. Change 'password_here' to your Arvixe MySQL database password (e.g. 'wpSQLdbPassword$')
  15. For the last define, 'localhost' - leave this alone. Arvixe uses 'localhost'
  16. Save this file 'wp-config.php'
  17. Create a new website on Arvixe and use FileZilla to upload this WordPress installation to your Arvixe website.
  18. Note: if you want to use this as a blog, as part of a larger ASP.Net website, add a blog directory to that website, and upload it to the blog directory.

Thursday, May 27, 2010

Apple Passes Microsoft as No. 1 in Tech

The big buzz today is about Apple overtaking Microsoft as the lead Hi Tech company in the US.
Apple Passes Microsoft as No. 1 in Tech


Last year Apple was predicted to double its sales of iPhones and iPods. This year they have over 89% of the smart phone market. I went into my local Sprint store to look at the competition. I looked at the Google Android, as the nicest smart phone they had. The Sprint sales rep said that it is selling well. They plan to get iPhones in when the AT&T exclusive contract allows.

I asked to see a Windows phone. The Windows 7 phone is not quite out yet. I played with it awhile. It reminded me of the older Windows phone which I tried and returned because it would blue screen and needed to be rebooted now and then. Alas, even as a Microsoft .Net software developer, when it come to phones, I want a phone that doesn't have to be rebooted when I want to answer a call.

I asked the Sprint sales rep how the Windows phone was selling. He said they only sold 2 out of this store. He said it is only good for business users. People are buying the Google Android and Blackberry.

Time to market is tough. The Windows 7 phone is coming very soon, and will be competing with the Google Android in the market of conservatives who wouldn't want to be caught dead with an iPhone or iPod in their pocket.

As a Microsoft .Net software developer, I'm looking at the big picture here. Microsoft's new .Net architecture includes Silverlight. Silverlight doesn't run on iPhones. iPhones have 89% of the market. The public world wide is increasingly moving to smart phones as their internet connection and away from desktops and even laptops. As a Hi-Tech geek who wants to keep up with the latest trends, this moves me away from Silverlight and towards Cloud Computing, and internet apps that are iPhone and iPad compatible.

The world is going crazy over the iPad. There was a Windows version, but it was not widely accepted. What is the secret sauce? It doesn't have to be re-booted, it's friendly, simple, beautiful, clean, and has personality. Windows Tablet PC came to market first, but really... Put it side by side next to an iPad. The world tried the Tablet PC and it just doesn't make it.

Sunday, April 25, 2010

Facebook badges


Did you know you can put a facebook link on your blog? I stumbled upon this today. I'm not clueless and learning Facebook. I joined 2 weeks ago and I'm lost and learning.

Please comment and give me a clue!

Here is a photo from our Robotics website... LORobotics.org

Saturday, July 4, 2009

OMG!!! I got a comment on my blog!

OMG!!! I got a comment on my blog!

So far I have gone into my dashboard and selected the blog that I got a comment from.
Freaky. I got this email in my Gmail inbox from someone and I had to do a double take.
Did this guy have my email address, or is this a forward from Blogger.
It is an email Forward from Blogger!
So what do I do next? In my Dashboard I selected the blog with the in coming comment and found looked for Comments.
I clicked on Posting tab > Comment Moderation tab.

What do I do next? Stay posted. I will figure it out and write about this soon.

Friday, July 3, 2009

Followers of your blog


I'm wondering how you get people to link to your blog. My friends say that is not how it's done. There is a section on the sidebar called Followers. I now have two of my friends as followers. :)
My friend Denice is one of my Followers. She has a blog called Quaffing Wine

I went to her blog and figured out how to follow hers. I scrolled down to Followers on the sidebar and clicked on the Follow button. A popup appears to add viewers as a Follower, as in the image to the right.

Here I added my photo, and added links to my websites and blogs.
It's pretty easy.
Here's an image of how to add a link.
I added my blogs and my websites:
Then I saw you can sign into the Following section. When I signed in, I found my friends and a link to invite others.

Then I went back to QuaffingWine by clicking the back to Quaffing Wine link.

The blog updates and shows my photo. You can click on my photo, and it shows all my links!

How cool it that?

Sunday, June 28, 2009

Labels, tags, keywords

What are Labels?
See my recent post on Oops! I forgot the tags!
In the lower right hand corner of the post text area, is a text box for Labels.
Labels are like website metatags.
So what are Labels and what are tags?
Labels and metatags are used by search engines that use keyword search as a way to find out what they content of your post is about.
This is in the realm of SEO - Search Engine Optimization.

If you are writing on one subject, your posts may have the same Labels (tags, keywords) on each post.

Let's say your topic is Cats. Add cats as a Label to each of your posts.
If one post talks about Whole Foods maintenance cat food which is only $2.49 for a 5 pound bag of great cat food at a bargain price - the best price in town,
then add Labels that include Whole Foods, cat food, bargain, and cat to your Labels. See example by looking at the Labels on this post.

These Labels are keywords, which search engines, web spiders, and other content search enginges use to categorize your post.