|
I want a suggestion on the following example :
Is it better to throw custom exception from an method which checks before inserting employee detail that particular employee's email already registered and catch that exception in my aspx.cs page or say view layer.
or
return error Number, something like -999 if duplicate email found.
from a method and then use conditional statement.
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
Exception handling is always better
|
|
|
|
|
.NET in general uses exceptions, so I say stay consistent.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Hi
I am trying to store the images using asp.net browser control ie, fileupload. .Its with store the images in to the databse where i used as sqlserver as backend. It store but, after that i am trying to retrive those images through listview from backend. But here i am getting no error but no images are there in images.I need the names of the images in the listview from backend while clicking a particular image it should be enlarge in image control.Thanks in advance.Please help me.
In default.aspx.cs page:
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DigitalSignageConnectionString2"].ConnectionString.ToString());
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BthSnd_Click(object sender, EventArgs e)
{
con.open();
SqlCommand mycommand = new SqlCommand("INSERT INTO Image_DiSig([image], [text],[path],[image1]) VALUES (@image, @text,@imgpath) ", con);
string apppath = Request.PhysicalApplicationPath;
FileUpload1.SaveAs(apppath + "images\\" + FileUpload1.FileName);
string imgpath = apppath + "images\\" + FileUpload1.FileName;
FileStream fs = File.OpenRead(imgpath);
byte[] imagedata = new byte[fs.Length];
mycommand.Parameters.AddWithValue("@image", imagedata);
mycommand.Parameters.AddWithValue("@text", TextBox1.Text);
mycommand.Parameters.AddWithValue("@imgpath", apppath);
mycommand.ExecuteNonQuery();
con.Close();
}
public string FormatURL2(object strArgument) //used to get that image bytes(while tracing its picking that bytes but not converting into image)
{
return ("Default2.aspx?id=" + strArgument);
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select * from Image_DiSig",con);
DataSet ds = new DataSet();
da.Fill(ds);
ListView1.DataSource = ds;
ListView1.DataBind();
}
protected void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
Image1.ImageUrl = ListView1.SelectedValue.ToString();
}
in default.aspx source page:
<asp:ListView ID="ListView1" runat="server"
onselectedindexchanged="ListView1_SelectedIndexChanged" SelectedIndex="0" >
<LayoutTemplate>
<div style="border:dotted 1px black;">
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</div>
</LayoutTemplate>
<ItemTemplate>
<img alt="name" align="middle" height="50px" width="100px" name="Image1" src='<%# FormatURL2(DataBinder.Eval(Container.DataItem, "id")) %>' />
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:DigitalSignageConnectionString2 %>"
SelectCommand="SELECT * FROM [Image_DiSig]"></asp:SqlDataSource>
in default2.aspx.cs:
public partial class Default2 : System.Web.UI.Page
{
SqlCommand cmdd = new SqlCommand();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DigitalSignageConnectionString2"].ConnectionString.ToString());
protected void Page_Load(object sender, EventArgs e)
{
string strImageID = Request.QueryString["id"];
try
{
conn.Open();
SqlDataReader dr = null;
cmdd = new SqlCommand("select image from Image_DiSig where id=" + strImageID,conn);
dr = cmdd.ExecuteReader();
while (dr.Read())
{
if (dr["image"].ToString() == "")
{
Response.Write("no image");
}
else
{
byte[] img = (byte[])(dr["image"]);
Response.BinaryWrite(img);
}
}
}
catch (Exception ee)
{
Response.Write(ee.Message);
}
finally
{
conn.Close();
}
}
}
With Regards
Ch.Gayatri Subudhi
|
|
|
|
|
If nothing gets returned you need to debug your SQL. Otherwise, you may just need to write a MIME type. Spend some time in the debugger, and get back to us when you can tell us what is specifically happening.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Sir,
No error coming while debugging then why its not converting from byte to image formate i wrote the code for that but no output is coming.
With Regards
Ch.Gayatri Subudhi
|
|
|
|
|
hi friend
i upload the file below error occured...
Access to the path 'D:\aesweb\WebSite\Images\banner_bulb.gif' is denied.
regards
saravanan
Known Is Drop.Unknown Is Ocean
|
|
|
|
|
Apparently, you don't have access to that file. Perhaps you might consider telling us what code causes this error, and when it happens. Saying 'I upload the file' doesn't tell us much. Did you try to upload a new file to your images folder and then access it ? How did you try to access it ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
if you r using Ajax u need to give trigger tag for that upload control.
otherwise change that file('D:\aesweb\WebSite\Images\banner_bulb.gif) property readonly false.
|
|
|
|
|
saravanan05 wrote: i upload the file below error occured...
Access to the path 'D:\aesweb\WebSite\Images\banner_bulb.gif' is denied.
It may be cause of user does not have the write permission on that folder.
Possible Solution :
1. Give the write access to that folder.
2. [If you have deployed it in IIS] Create a separate application pool, change its identity of local system, assign that application to your virtual directory.
Your problem will be resolved.
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
hi,
i intend to insert some variable which got string of data into specific cell in an existing excel file in localhost, eg: variable1 insert to cell E,3, variable2 insert to cell G,6.....
my scenario is the existing excel file is a preformatted and i dont know how to insert certain data into specific cell in the excel file...
anyone can giv some recommend solution? Pls help.
|
|
|
|
|
This has nothing to do with ASP.NET, even though you're doing it within the context of an ASP.NET site. You're modifying a local Excel file, you'd do better to ask in the right forum for the language you're using.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
How you r Exporting that Excel File...?
|
|
|
|
|
oops, forgot to tell that the program is an offline system which use asp.net with vb.... there is juz 1 user for that program, and the excel file is place in localhost.
thanks for help, any others recommend solution?
|
|
|
|
|
Tonight I copied an ASP 2.0 web site onto a client's machine, and lo! It did not work. It works perfectly on mine, under built in debugger and under IIS 7, and two weeks ago, it worked perfectly on his machine under IIS 6.
The only changes I have made are upgrading telerik RadGrid etc. to Q1 2009, and some refactoring. The application fails on two entry point web forms. Both have a RadGrid, which uses a User Control for its editing pop-up. Both forms fail to compile, with a 'Type or namespace JobEditControl not found" error, on a line like this:
var editControl = e.Item.FindControl(GridEditFormItem.EditFormUserControlID) as JobEditControl;
The control is not referenced in the markup, as it never appears on there, and as I understand it, it should be compiled into the same default namespace as the page is compiled into when first hot.
The machine is still serving user controls properly, i.e. the .ascx handler appears healthy, and a quick test page containing a quick test control I added worked fine.
Another developer was busy on the machine before me, also installing an ASP.NET application, but I can't think of anything he would have changed. Even being my competition...
|
|
|
|
|
i have some hyperlinks on a form.I have set the navigate url of all the hyperlinks to a single destination page("display.aspx")i.e.clicking on ne of the hyperlinks would take you to the same page "display.aspx"..
but based on which hyperlink i hav selected, accordingly values from database will be retrieved and will displayed in "display.aspx"..
for eg:
suppose i hav 3 hyperlinks say :
1)programmer
2)business analyst
3)software engineer
and if i click on programmer then accordingly query will be executed in the page load event of "display.aspx" and info abt programmer will be retrieved from database and displayed in a gridview.
plzz suggest some solution..
|
|
|
|
|
what you need is query string
display.aspx?user=programmer<br />
display.aspx?user=analyst<br />
display.aspx?user=engineer
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
You can use the hyperlink's command event to get the command arguments from which hyperlink you clicked.
|
|
|
|
|
hi yusuf thanx for the answer,but can u elaborate it a bit more..
where to write these querystring,in which event of hyperlink?
|
|
|
|
|
You have to just pass the selected values through
query string
Click Here
Vinod Kr.
|
|
|
|
|
hey vinodkrebc,
plzz paste the link...
|
|
|
|
|
Click Here
you can write any page instead of default.aspx and the data member instead of Id from datasource
|
|
|
|
|
thanx .mah problem is solved
i used the anchor tag instead of hyperlink control from the toolbox...
|
|
|
|
|
Hi,
I have an application in which I am trying to retrieve a user's password. The code is as follows:-
1 MembershipUser resetPass = MyUsers[UserInfo.Rows[e.NewSelectedIndex].Cells[0].Text];
2 string password = resetPass.GetPassword();
However on execution I am hit with the following error:-
This Membership Provider has not been configured to support password retrieval.
I have tried the following steps to resolve this issue but to no avail:-
In the WebConfig in I have modified the <Membership></Membership> tag to reflect the following:-
<membership>
<providers>
<clear/>
<add name=”AspNetSqlMembershipProvider”
connectionStringName=”247Db”
minRequiredPasswordLength=”4″
minRequiredNonalphanumericCharacters=”0″
type=”System.Web.Security.SqlMembershipProvider”
applicationName=”/247App”
enablePasswordRetrieval=”true”
requiresQuestionAndAnswer=”false”
passwordFormat=”Encrypted”
requiresUniqueEmail=”false” />
</providers>
</membership>
I also added a machineKey to support the setup above as follows:-
1 <machineKey validationKey="11D7D8362528F04266ACACDDEA7..."
2 decryptionKey=”4C0…”
3 validation=”SHA1″/>
However, now i get the following error:-
"Hashed passwords cannot be encoded".
I am guessing this is because the passwordFormat property in the web.config was "Hashed" befrore I changed it to Encrypted. Nevertheless, what should I do ?
Thanks
|
|
|
|
|
Dear sir, how can I send email to a particular email with attachment file? Can I check this program from localhost?
|
|
|
|