|
The example you referenced shows how to load a file on the server into a memory stream, and then convert it to a zip or compressed file, and then package the file for download. Then it will prompt the browser to download the zip file.
The 2nd example on your reference shows a better way to write the code, the first example that you copied is the version that doesn't work very well, and has problems. Use the 2nd example.
But in hindsight, the codes function doesn't match what you want to do.
Could of swore that you want to upload the compressed file to the server.
So in button click, on the client machine, in the first code block where you read the file data from the database, you just read the reader, and get the bytes and store them in a buffer. Then close the database, exit the data function.
Now chop up the bytes into 4096 blocks or what ever value you choose.
So measure the byte buffer and get it's length, then divide the length by 4096, that's how many loops you need.
And then seek or start at 0, and grab 4096 chuck of bytes, then write the file, grad the next 4096 chunk of bytes, write the file and so on.
Make sure your files exist in a temp storage place like App_Data.
Get that working smooth first before you try to upload the files to the server.
|
|
|
|
|
Hi All,
I am using an asp.net application page to show the contents on the page with line break and OR image on the line break, I am not yet done with image itself, the problem is image appears at an inappropriate space or never appears as I have been trying with several options. Here I am putting this code that I am currently using. Can you please advice me or help me with any idea or code snippet or link any thing can be helpful, thank and your help is much appreciated as I am getting tired with this, searching on the internet no help so far but still trying.
Thanks in advance and here is the code.
<ol>
<li id="first-option" class="first-option">
<div class="paren"></div>
<div class="full col">
<label for="txtFirstName">First Name</label>
<asp:TextBox ID="txtFirstName" runat="server" ClientIDMode="Static" Enabled="false" />
</div>
<div class="full col">
<label for="txtLastName">Last Name</label>
<asp:TextBox ID="txtLastName" runat="server" ClientIDMode="Static" Enabled="false" />
</div>
<div class="full col">
<label for="txtBirthDate">Date of Birth</label>
<elms:DateTextBox ID="txtBirthDate" runat="server" ClientIDMode="Static" />
</div>
<div class="full col">
<label for="txtEmailAddress">Email Address</label>
<asp:TextBox ID="txtEmailAddress" runat="server" ClientIDMode="Static" />
</div>
<div class="full col">
<label for="txtEmailAddress2">Verify Email Address</label>
<asp:TextBox ID="txtEmailAddress2" runat="server" ClientIDMode="Static" />
</div>
</li>
<li id="or-divider" class="or-divider"><span></span></li>
<li id="second-option" class="second-option">
<div class="paren"></div>
<div class="full col">
<label for="txtStarsId" runat="server">STARS ID</label>
<asp:TextBox ID="txtStarsId" runat="server" ClientIDMode="Static" />
</div>
</li>
</ol>
<div class="action-buttons">
<asp:Button ID="btnSave" ClientIDMode="Static" runat="server" Text="Save" />
<asp:Button ID="btnCancel" ClientIDMode="Static" runat="server" Text="Cancel" />
</div>
CSS here, but with this the OR appears at the bottom and over the save and cancel buttons, which is not good and the numbers 1 and 2 appears over the first li's items, not useful and I don't why 1 appears only half, please help me if you can
or-divider
{
position:absolute;
border:none;
left:50%;
top:50%;
transform:translate(-50%,-50%);
}
.or-divider > span
{
background:transparent url('../../../images/OR-Small.png') no-repeat top center;
background-color:White;
position:absolute;
font-size:1.3em;
font-weight:bold;
top: inherit;
display: inline-block;
left: 40%;
height:20px;
width:80px;
z-index:1000;
}
<h1>or-divider + li</h1>
{
padding-top:30px;
}
.my-container > ol > li > span:first-child
{
display:block;
margin-bottom:5px;
}
.my-container > ol > li:first-child > select,
.my-container > ol > li:first-child > .chosen-container
{
width:100%;
margin-bottom:5px;
}
div.paren
{
position:absolute;
left:25px;
top:0;
height:47px;
width:15px;
background:transparent url('../../../images/Close-Paren.png') no-repeat left top;
}
<h1>first-option,</h1>
<h1>second-option</h1>
{
position:relative;
padding-left:50px;
}
<h1>first-option</h1>
{
background:transparent url('../../../images/1.png') no-repeat 2px 3px;
}
<h1>second-option</h1>
{
min-height:40px;
background:transparent url('../../../images/2.png') no-repeat left 33px;
}
<h1>second-option div.paren</h1>
{
background-position:left 30px;
height:77px;
}
"There is enough hatred in the world, lets spread love compassion and affection."
|
|
|
|
|
You can only set CSS properties that the span tag supports. Google span tag, the W3 website will show you what the element currently supports.
A span tag is just an inline-element that supports text. I know you can make a span tag a button as well, and do some other stuff with it.
But if the element is text empty, it won't display, to the best of my knowledge.
I would hard code the image location, and not use the dots. You can drag the image to the CSS file and it should calculate the path.
I know there's a way to use the 2nd class as a child or the 1st class, but you should make sure it works first before until you get really good at typing CSS off the top of your head.
left 50% - 50% of what?
You should Google li as well and see what you can do with it.
.li_divider
{
border:none;
left:50%;
}
span.li_divider
{
background:transparent url('/images/OR-Small.png') no-repeat top center;
background-color:White;
font-size:1.3em;
font-weight:bold;
}
Similiar Issue to look at.
http://stackoverflow.com/questions/16068683/the-background-image-in-the-span-wont-show-without-any-text-in-the-span-tag[^]
|
|
|
|
|
I am using table value parameter for insertion into four table and four table value parameters are used but after the insertion my application gets hangs on any one can assist.
|
|
|
|
|
I'm not able to visual that. Perhaps you should post the code you wrote for this.
Do you read the How to get an answer to your question?
If it's a database update or write, it's usually because an error occurred and you didn't close your connection.
Try Catch Finally
|
|
|
|
|
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
If Not Page.IsValid Then Return
Dim blnIsUpdate As Boolean = False
Dim hasedBytes As Byte()
Dim strPassword As String = String.Empty
Dim md5Hasher As New MD5CryptoServiceProvider()
If Not litUserId.Text.Trim().Length.Equals(0) Then blnIsUpdate = True
Dim cnnContact As New SqlConnection(AppSettings("DbSqlPortal"))
Dim cmdContact As New SqlCommand("spAdminSaveUsers", cnnContact)
Dim IDs As Integer = Nothing
Dim trnContact As SqlTransaction = Nothing
cmdContact.CommandType = CommandType.StoredProcedure
hasedBytes = md5Hasher.ComputeHash(New UTF8Encoding().GetBytes((txtPassword.Text.Trim() & txtEmail.Text.Trim())))
' GetDistrictID()
'If GetDistrictId() > 0 Then
' DisplayMessage(Me.Master.MessageBox, "A User with same District and Same user role already exists.", "Record Exists", MessageBoxTypes.Warning)
'Else
Try
With cmdContact.Parameters
If blnIsUpdate Then
.Add("@UserId", SqlDbType.BigInt).Value = CInt(litUserId.Text.Trim())
Else
.Add("@UserId", SqlDbType.BigInt).Value = DBNull.Value
End If
.Add("@FullName", SqlDbType.NVarChar).Value = txtFullName.Text.Trim()
.Add("@Email", SqlDbType.NVarChar).Value = txtEmail.Text.Trim()
.Add("@Password", SqlDbType.VarChar).Value = base64Encode(txtPassword.Text)
'txtPassword.Text.Trim()
'Convert.ToBase64String(hasedBytes)
.Add("@SecurityQuestion", SqlDbType.VarChar).Value = ddlSecurityQuestions.SelectedItem.Text
.Add("@SecurityAnswer", SqlDbType.VarChar).Value = txtAnswer.Text.Trim()
.Add("@UserTypes", SqlDbType.TinyInt).Value = ddlUserTypes.SelectedValue
.Add("@IsActive", SqlDbType.Bit).Value = chkActive.Checked
.Add("@DistrictId", SqlDbType.TinyInt).Value = CheckBoxList1.SelectedValue
.Add("@IsAdmin", SqlDbType.Bit).Value = chkAdmin.Checked
.Add("@IPAddress", SqlDbType.VarChar).Value = Request.UserHostAddress
.Add("@Result", SqlDbType.Char, 1).Direction = ParameterDirection.Output
.Add("@ReturnId", SqlDbType.BigInt).Direction = ParameterDirection.Output
If ChkIsReportAble.Checked = False Then
.Add("@IsReportable", SqlDbType.Bit).Value = False
Else
.Add("@IsReportable", SqlDbType.Bit).Value = ChkIsReportAble.Checked
End If
If ChkIsReportAble.Checked Then
.Add("@ReporintPerson", SqlDbType.TinyInt).Value = CInt(ddlReporintUser.SelectedValue)
Else
.Add("@ReporintPerson", SqlDbType.TinyInt).Value = DBNull.Value
End If
End With
cnnContact.Open()
trnContact = cnnContact.BeginTransaction()
cmdContact.Transaction = trnContact
cmdContact.ExecuteNonQuery()
If CChar(cmdContact.Parameters("@Result").Value).Equals("E"c) Then
' Msg.Text = "The Record has been Successfully Submitted !"
DisplayMessage(Me.Master.MessageBox, "A User with same Email already exists.", "Record Exists", MessageBoxTypes.Warning)
'MessageBoxShow(Page, "This Record Exists Try with some other record!")
litUserId.Text = String.Empty
Return
End If
trnContact.Commit()
litUserId.Text = (cmdContact.Parameters("@ReturnId").Value)
If blnIsUpdate Then
Dim cmdsDistrict As New SqlCommand("spAdminDeleletUserAssociationNews", cnnContact)
cmdsDistrict.CommandType = CommandType.StoredProcedure
Try
With cmdsDistrict.Parameters
.Add("@UserId", SqlDbType.TinyInt).Value = litUserId.Text
.Add("@Result", SqlDbType.Char, 1).Direction = ParameterDirection.Output
End With
trnContact = cnnContact.BeginTransaction()
cmdsDistrict.Transaction = trnContact
cmdsDistrict.ExecuteNonQuery()
trnContact.Commit()
Catch ex As Exception
End Try
End If
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("DistrictId", GetType(Integer)), New DataColumn("DistrictName", GetType(String)), New DataColumn("UserID", GetType(Integer))})
Dim i As Integer = 0
Do While (i < CheckBoxList1.Items.Count)
If CheckBoxList1.Items(i).Selected Then
Dim id As Integer = Integer.Parse(CheckBoxList1.Items(i).Value)
Dim name As String = CheckBoxList1.Items(i).Text
Dim country As String = litUserId.Text
dt.Rows.Add(id, name, country)
End If
i = (i + 1)
Loop
If dt.Rows.Count > 0 Then
' cnnContact = New SqlConnection(AppSettings("DbSqlPortal"))
Using cmd As New SqlCommand("Insert_Customers")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnnContact
cmd.Parameters.AddWithValue("@tblCustomers", dt)
cmd.ExecuteNonQuery()
End Using
End If
Dim dt2 As New DataTable()
'Dim cnnCdf As SqlConnection = Nothing
dt2.Columns.AddRange(New DataColumn(3) {New DataColumn("TehsilId", GetType(Integer)), New DataColumn("TehsilName", GetType(String)), New DataColumn("DistrictId", GetType(Integer)), New DataColumn("UserID", GetType(Integer))})
Dim i2 As Integer = 0
Do While (i2 < CheckBoxList2.Items.Count)
If CheckBoxList2.Items(i2).Selected Then
Dim id As Integer = Integer.Parse(CheckBoxList2.Items(i2).Value)
hdnThil = id
Dim name As String = CheckBoxList2.Items(i2).Text
Dim country As String = litUserId.Text
Dim tId As Integer = GetDistrictIDoftehsilIds(CheckBoxList2.Items(i2).Value)
dt2.Rows.Add(id, name, tId, country)
End If
i2 = (i2 + 1)
Loop
If dt2.Rows.Count > 0 Then
Using cmd As New SqlCommand("Insert_Customersfourth")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnnContact
cmd.Parameters.AddWithValue("@tblCustomersfourth", dt2)
cmd.ExecuteNonQuery()
End Using
End If
Dim dt3 As New DataTable()
dt3.Columns.AddRange(New DataColumn(3) {New DataColumn("UCID", GetType(Integer)), New DataColumn("UCName", GetType(String)), New DataColumn("TehsilId", GetType(Integer)), New DataColumn("UserID", GetType(Integer))})
Dim i3 As Integer = 0
Do While (i3 < CheckBoxList3.Items.Count)
If CheckBoxList3.Items(i3).Selected Then
Dim id As Integer = Integer.Parse(CheckBoxList3.Items(i3).Value)
hdnUC = id
Dim name As String = CheckBoxList3.Items(i3).Text
Dim country As String = litUserId.Text
Dim Ucid As Integer = GetTehsilIDIds(CheckBoxList3.Items(i3).Value)
dt3.Rows.Add(id, name, Ucid, country)
End If
i3 = (i3 + 1)
Loop
If dt3.Rows.Count > 0 Then
Using cmd As New SqlCommand("Insert_CustomersThird")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnnContact
cmd.Parameters.AddWithValue("@tblCustomersThird", dt3)
cmd.ExecuteNonQuery()
End Using
End If
Dim dt4 As New DataTable()
dt4.Columns.AddRange(New DataColumn(3) {New DataColumn("VillageId", GetType(Integer)), New DataColumn("VillageName", GetType(String)), New DataColumn("UcID", GetType(Integer)), New DataColumn("UserID", GetType(Integer))})
Dim i4 As Integer = 0
Do While (i4 < CheckBoxList4.Items.Count)
If CheckBoxList4.Items(i4).Selected Then
Dim id As Integer = Integer.Parse(CheckBoxList4.Items(i4).Value)
hdnVillage = id
Dim name As String = CheckBoxList4.Items(i4).Text
Dim country As String = litUserId.Text
Dim Ucid As Integer = GetUCIDIds(CheckBoxList4.Items(i4).Value)
dt4.Rows.Add(id, name, Ucid, country)
End If
i4 = (i4 + 1)
Loop
If dt4.Rows.Count > 0 Then
Using cmd As New SqlCommand("Insert_CustomersSecond")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnnContact
cmd.Parameters.AddWithValue("@tblCustomersSecond", dt4)
cmd.ExecuteNonQuery()
End Using
End If
' Catch ex As Exception
'End Try
cnnContact.Close()
Dim strMessage As String = "A new User has successfully been created and saved."
If blnIsUpdate Then strMessage = "The selected User has successfully been updated and saved."
'lblMesssages.InnerText = "Welcome"
DisplayMessage(Me.Master.MessageBox, strMessage, "User Saved Successfully", MessageBoxTypes.Success)
SendMAilMessage()
' MVSearch.ActiveViewIndex = 0
SearchUsers()
'DisplayInitialPage()
Catch ex As Exception
If trnContact IsNot Nothing Then trnContact.Rollback()
DisplayMessage(Me.Master.MessageBox, "An unexpected error occurred while saving the Record. Please retry.", "Record Not Saved", MessageBoxTypes.Error)
Finally
DisposeDataObjects(, , cmdContact, cnnContact)
End Try
End Sub
|
|
|
|
|
How do you know this works?
cnnContact.Open()
trnContact = cnnContact.BeginTransaction()
cmdContact.Transaction = trnContact
cmdContact.ExecuteNonQuery()
Usually you try to keep your SQL more compact in a separate clean function.
Consider a simple request for an ID
This example opens the connection, reads the reader, closes the reader,
With the Try Catch Finally, if the connection or command fails, then the finally will close the connection.
Dim connStr As string = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
Dim query as string = "SELECT ID FROM TABLE"
Dim conn as New SqlConnection(query)
Dim cmd as New SqlCommand(query, conn)
Try
conn.open()
Dim reader as SQLDataReader = cmd.ExecuteReader()
while reader.Read()
pValue = reader.GetInt32(0)
End While
reader.Close()
Catch ex as SQLException
'If there is an error, this will tell you why, so fix the error
' but without the finally, the conn will be left open,
'So if you get too many conn open to the sql server, the sql server will hang
Finally
conn.Close()
End Try
modified 17-Apr-15 13:55pm.
|
|
|
|
|
Dear I am using finally at the end to dispose all the objects after transaction commit , what you suggest how to modify my code ? which i have wrote above
|
|
|
|
|
Well in order to find your problem, you have to track it down first.
My previous post suggested using the Try Catch and check for any exceptions thrown.
So you have to walk the code line by line using F5 debug and check for an exception.
As far as modifying the code, instead of a large block of code, you want to break the code down into a couple of reusable function.
I like taking all the database calls, and placing them in several separate functions.
Sort of like having a Data Access Layer, and Business Logic Layer, in which the 2 are separated.
Then it's easier to just go the suspected function and debug it, saves time in the long run.
But that's another subject.
Like I said, your connection may not be closing after and error, and your opening a new one over and over, causing a stall in execution.
|
|
|
|
|
Dear Sir, Thanks for your time and response , I have used seperate function and while debugging it does not show any error and after the end sub of the function it struck in loop and if i insert smaller records like 2-3 villages just it works fine ..
Again Thanks
|
|
|
|
|
Go through it with a fine tooth comb and keep checking
Here's an error I overlooked, the checkbox is boolean true or false, so it wrote an bit to the parameter of 0 or 1
Or perhaps it's a dropdown list since you used selected value.
.Add("@DistrictId", SqlDbType.TinyInt).Value = CheckBoxList1.SelectedValue
That's a lot data to insert all at once. You know that data writes and updates take longer to perform on the SQL server, in terms of time. And then you called a stored procedure after that.
You have an error somewhere. finding the error is easier if your code is more organized.
Maybe instead of so many partial writes, you gather all your data first, and package it up in a class, structure or model, and then do 1 write to the database. You just pass the class or structure to the database function, and do the write. On multiple records, you just loop the database write function.
https://msdn.microsoft.com/en-us/library/aa289521%28v=vs.71%29.aspx[^]
http://www.functionx.com/visualbasic/Lesson19.htm[^]
In a seperate file
Public Structure structure_accountInfo
Public m_firstName as string
Public m_lastName as string
End Structure
In a seperate file
Public Shared Function account_db_update(ByVal sAI as structure_accountInfo) as Integer
Dim dwExitCode As Integer = 2
Dim connStr As String = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
Dim conn As New SqlConnection(connStr)
Dim query as string = _
"UPDATE TABLE " & _
" SET " & _
" firstName = @firstName " & _
", lastName = @lastName " & _
" WHERE ID = @ID "
Dim cmd As New SqlCommand(query, conn)
Dim param__FirstName As SqlParameter
param__FirstName = New SqlParameter("@FirstName", SqlDbType.VarChar, 80)
param__FirstName.Value = sAI.m_firstName
cmd.Parameters.Add(param__FirstName)
Dim param__LastName As SqlParameter
param__LastName = New SqlParameter("@LastName", SqlDbType.VarChar, 80)
param__LastName.Value = sAI.m_lastName
cmd.Parameters.Add(param__LastName)
Try
conn.Open()
cmd.ExecuteNonQuery();
dwExitCode = 0
Catch ex As Exception
dwExitCode = 1
Finally
conn.Close()
conn = Nothing
cmd = Nothing
End Try
return dwExitCode
End Function
In a seperate file
Dim sAI as new structure_accountInfo()
sAI.m_firstName = txt_firstName.text.trim
sai,m_lastName = txt_lastName.Trim
account_db_update(sAI)
You have so much code in the first example, I can't help you isolate your error until you isolate it down to a more narrow focus.
|
|
|
|
|
Hi,
I am facing some issue with my gridview. I have a webform with 1 button, 5 textbox (2 with date picker) and 1 dropdown list. The issue is when I perform search operation based on these controls texts, for few click on button I get the required data displayed on gridview but after few click it stop displaying that data. any solution to this.
P.S: VS 2013 framework 4.5, asp.net
|
|
|
|
|
Need more info. No one can help without seeing relevant code and without a clear description of the issue.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
What do you mean bu stop displaying? Have you checked it may be reset in response to any postback. But anyways will try to help if you elaborate more.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
When I perform couple of search operation using some combination it is working fine after that the grid view is displaying no data. and no there is no postback data
|
|
|
|
|
Are you binding data back to gridview control after you received your search results?
If you add your code it may help to find the issue, we cannot figure out it without code.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
I just keep getting a message about
"Over the last 24 hours, Googlebot encountered 1 errors while attempting to access your robots.txt. To ensure that we didn't crawl any pages listed in that file, we postponed our crawl. Your site's overall robots.txt error rate is 100.0%. You can see more details about these errors in Webmaster Tools. "
but our web site has no robots.txt file and our web site address is www.bba-reman.com please guide me how to get rid of this problem. thanks
tbhattacharjee
|
|
|
|
|
Try adding an empty robots.txt file to the root of your site.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ignore it.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hello,
I have a task to read a excel file using asp.net. My problem is that I have excel file containing text in different fonts like some text in "Times New Roman" and some text in "Shri Dev 078e". I didn't get any solution how to achieve the desire result. Example the below text:
eãX "OFFICES" Ho$ Ajam| H$mo AbJ-AbJ {H$VZo VarH$m| go gOm`m Om gH$Vm h¡?
In the above text containing font "SHREE-DEV-0708E" as well as "OFFICES" in Times new roman.
when i store that text in my db i have to store the text with font name as well.
Is their any logic to put some kind of special character within start and end of the word which is in different font.
|
|
|
|
|
Font information is stored separately from the actual characters, so you need to add some extra field to your database records to hold the information.
|
|
|
|
|
Thanks Richard MacCutchan,
I already have column in my database, but i am not able to track the font name from cell. if you have any code or some logic than you must let me know.
|
|
|
|
|
|
Doing some discovery work related to taking a 8 year old ASP, accessDB application and rehosting to a cloud VM (current app is running on a backserver behind a firewall and don't have access). My basic question is what are the key attributes I need to know in order to rehost the application. I understand the basic questions (ASP version, memory req, etc) but would like some input on other information I need to know so I can configure the new environment and have the application run. I have very little information related to the Apps user interface, business logic and data source connections other than it is ASP/Access with some SQL. Any input would be helpful. Thanks...
|
|
|
|
|
I remember back in the day 2003, most of those asp classic websites were pretty small in size, and had a database file, usually a MDF file located someone in one of the folders. They used a ADO adapter to talk to the file.
They were easy to setup, just copy the project into a folder, setup IIS server 4 or 5, point it to the website and go.
The database file location was hard coded into the code, so you may need to adjust it.
they were developed on Windows XP, and used Server 2003 to host them.
A gig of ram should do it.
Just create a Server 2003 virtual machine, copy the project into a dedicated hard drive with a root folder of
www\new website
and give it a run. You may need to fix some data paths in the code.
|
|
|
|
|