Advertisement
| Hall of Fame |
|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: |
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient; //had to add to connect to sql
namespace FileTransfer2
{
public partial class FileUpload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void lbtnReturntoHome_Click(object sender, EventArgs e)
{
Response.Redirect("default.aspx");
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
//lblResults.Text = "";
if (FileUpload1.HasFile)
try
{
string folderPath = ConfigurationManager.AppSettings["UploadDirectory"];
string filePath = System.IO.Path.Combine(folderPath, FileUpload1.FileName); //concatenates path + file name
FileUpload1.SaveAs(filePath);
lblResults.Text = "File Successfully Uploaded: <br>" + "File name: " +
FileUpload1.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
ClientFileRepository repository = new ClientFileRepository();
int fileid = repository.InsertNewFile(FileUpload1.FileName, txtDescription.Text, filePath);
string UserName = User.Identity.Name;
//This is where I am having a problem
ClientFileRepository repository = new ClientFileRepository();
DataTable UserGuid = repository.GetUserGuid(UserName);
if (UserGuid != null && UserGuid.Rows.Count > 0)
{
string UserID = UserGuid.Rows[0]["UserId"].ToString();
Response.Write(UserID);
}
else
{
Response.Write("No userid found.");
}
lblError.Text = "";
}
catch (Exception ex) //this should catch if jibberish is entered but it doesn't
{
//lblError.Text = "Error: File was not found.";
Response.Write("Error: " + ex.Message);
}
else
{
txtDescription.Text = "";
lblResults.Text = "";
lblError.Text = "You have not specified a file.";
}
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace FileTransfer2
{
public class ClientFileRepository
{
public int InsertNewFile(string fileName, string description, string clientfile)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FileTransferConnectionString"].ToString()))
{
using (SqlCommand cmd = new SqlCommand("InsertNewFile", conn)) //stored proc name
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@FileName", fileName);
cmd.Parameters.AddWithValue("@Description", description);
cmd.Parameters.AddWithValue("@ClientFile", clientfile);
conn.Open();
return int.Parse(cmd.ExecuteScalar().ToString()); //returns scope_identity from proc
}
}
}
public DataTable GetFileInfo(int id)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FileTransferConnectionString"].ToString()))
{
using (SqlCommand cmd = new SqlCommand("getFilebyFileID", conn)) //stored proc name
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", id);
SqlDataAdapter daFilesbyId = new SqlDataAdapter(cmd);
DataTable FilesbyId = new DataTable();
conn.Open();
daFilesbyId.Fill(FilesbyId);
return FilesbyId;
}
}
}
public DataTable GetUserGuid(string UserName)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FileTransferConnectionString"].ToString()))
{
using (SqlCommand cmd = new SqlCommand("getUserID", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", UserName);
SqlDataAdapter daGetUserGuid = new SqlDataAdapter(cmd);
DataTable UserGuid = new DataTable();
conn.Open();
daGetUserGuid.Fill(UserGuid);
return UserGuid;
}
}
}
}
}
SQL:
ALTER proc [dbo].[getUserID]
@UserName nvarchar(256)
AS
select
u.UserId
from aspnet_Users u
where u.UserName = @UserName
|