|
Sorry but I do not know the answer, but I would expect more information to appear in the error message or some log entry to be made, either in the project directory or in the system event log.
|
|
|
|
|
In the title you are complain about 2012, but you show us that you run a repair on 2015!
How that connected? (2012 includes MVC4, so no need of 2015 for that)
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
brother i just told u the pattern, copy and paste from stack overflow
but i did as i required for 2012 so without making joke tell me the solution otherwise do ur work ok
|
|
|
|
|
You missed the point! I'm NOT your debugger - you have one built in in your VS!!!
With that attitude you will spend an eternity to solve such problems...
You want answers? Give details! We do not ask questions for nothing, but to help and clarify!!!
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
ok brother sorry dont mind . i had found the solution
|
|
|
|
|
Hello,
I have very perplexing issue. For years I have made websites with Asp.net and have used some lines of code to export gridview data to an excel work sheet. Last week the code just stopped working, I did not change anything with the code to any of the points in my website that exports to excel, it just stopped working.
I have tested it on both my development server and production server, same thing. It still pops up an excel link but when you open the excel file there is nothing, and it doesn't even generate a blank workbook.
Here is the code I use:
public static void DGToExcel(System.Web.UI.Control ctl)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
// ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
I have absolutely no idea what is going on here and why code I have been using for years would stop working. If someone could shed some light on this issue I would grealt appreciate it. Thanks.
Marc
|
|
|
|
|
The thing is, you're NOT exporting the grid to an Excel file. You're sending an HTML document to the browser, but "lying" in the headers and telling it the response is an Excel document. Excel is then doing its best to convert the HTML into an Excel worksheet.
Not only does this limit your control over the formatting and prevent you from using any "advanced" features of Excel, it also leaves you subject to the whims of whatever version of Excel the user has installed. When you run into strange problems like this, there is often no obvious cause or workaround.
If you're lucky, you might be able to track it down to a recent security update, or a change to the users' settings. But telling your users to uninstall security updates just to get your code working again isn't a sensible option.
You'll probably have better luck if you change your code to create a real Excel file. Since you're using ASP.NET, you can't use Office Interop[^]. But there are several open-source libraries which are safe to use from server-side code:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Okay I'm following you, I will look into those other options of creating an excel read file. I actually remember that's how I did it an a program I made many years ago but I have since lost that code.
Thank you very much for your reply.
|
|
|
|
|
In my Relation i have two tables relation (one to many)
table country
Id (primary key)
Countryname
table City
Id (primary key)
Cityname
Countryid (forign key)
I have controller City have the following function
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LinqProject.Models;
namespace LinqProject.Controllers
{
public class CityController : Controller
{
mytaskdbEntities db = new mytaskdbEntities();
public ActionResult List()
{
return View(db.Cities.ToList());
}
and in view of List as following
<body>
<div>
<table>
@foreach (var item in Model)
{
<tr><td>@item.Cityname</td><td>@item.Country.Countryname</td></tr>
}
</table>
</div>
</body>
What i need actually adding delete button to view of list of city
and i can delete city when click button delete
how to do deleting record by linq
the final result as following
USA NEWYORK DELETEBUTTON
USA WASHINTON DELETEBUTTON
FRANCE PARIS DELETEBUTTON
when click delete button for row USA NEWYORK it will delete
and remaining two record
USA WASHINTON DELETEBUTTON
FRANCE PARIS DELETEBUTTON
|
|
|
|
|
You can add button control with command 'delete' in the buttons. When you click pass the id of city to be deleted to the controller. In the controller you need to receive two parameters command and id of the city.
What's your issue ?
|
|
|
|
|
Is there any way to somehow combine the data from two models and THEN map them *both* to the same viewModel in the context of an edit action?
I have never had to update several tables at once in an edit action in ASP.NET MVC with Entity Framework 6.1.3. This is the layout:
I have a DB table called "Address" which has fields for StreetNumber, StreetName, City, State, ZipCode. It has a *one-to-one* relationship with another table called Bars. As in, a bar can only have one address and one address can only have one bar.
Because I am storing this data in two separate tables, I am having a very difficult time trying to successfully implement an Edit action which takes data from **one form** (BarForm) and should update both the Bar and Address database tables. See my code:
**BarController**
public ActionResult Edit(int id)
{
var bar = _context.Bars.SingleOrDefault(m => m.Id == id);
var address = _context.Addresses.SingleOrDefault(a => a.BarId == id);
if (bar == null)
{
return HttpNotFound();
}
var viewModel = Mapper.Map<Bar, BarFormViewModel>(bar, new BarFormViewModel());
if (address == null)
{
address = new Address();
}
Mapper.Map<Address, BarFormViewModel>(address, viewModel);
viewModel.IsNew = false;
return View("BarForm", viewModel);
}
[ValidateAntiForgeryToken]
public ActionResult Save(BarFormViewModel bar)
{
if (!ModelState.IsValid)
{
var viewModel = Mapper.Map<BarFormViewModel, BarFormViewModel>(bar, new BarFormViewModel());
viewModel.IsNew = false;
return View("BarForm", viewModel);
}
if (bar.Id == 0)
{
var newbar = Mapper.Map<BarFormViewModel, Bar>(bar);
newbar.LastUpdated = DateTime.UtcNow;
_context.Bars.Add(newbar);
var addressToAdd = Mapper.Map<BarFormViewModel, Address>(bar);
_context.Addresses.Add(addressToAdd);
}
else
{
var barInDb = _context.Bars.Single(b => b.Id == bar.Id);
var addressInDb = _context.Addresses.Single(a => a.BarId == bar.Id);
Mapper.Map<BarFormViewModel, Bar>(bar, barInDb);
Mapper.Map<BarFormViewModel, Address>(bar, addressInDb);
}
_context.SaveChanges();
return RedirectToAction("Index", "Bar");
}
**Domain Models:**
public class Bar
{
public int Id { get; set; }
public string Name { get; set; }
[Required]
public string GooglePlaceId { get; set; }
public string SundayDiscounts { get; set; }
public string MondayDiscounts { get; set; }
public string TuesdayDiscounts { get; set; }
public string WednesdayDiscounts { get; set; }
public string ThursdayDiscounts { get; set; }
public string FridayDiscounts { get; set; }
public string SaturdayDiscounts { get; set; }
[Display(Name = "Last Updated")]
public DateTime LastUpdated { get; set; }
}
public class Address
{
public int Id { get; set; }
public int? Number { get; set; }
public string StreetName { get; set; }
public string City { get; set; }
public string State { get; set; }
[Required]
public int ZipCode { get; set; }
public Bar Bar { get; set; }
public int BarId { get; set; }
}
**View Model which includes both Address and Bar properties**:
{
public class BarFormViewModel
{
public int? Id { get; set; }
public string Name { get; set; }
[Required]
[Display(Name = "Google Place ID")]
public string GooglePlaceId { get; set; }
[Display(Name = "Sunday Happy Hour Info:")]
public string SundayDiscounts { get; set; }
[Display(Name = "Monday Happy Hour Info:")]
public string MondayDiscounts { get; set; }
[Display(Name = "Tuesday Happy Hour Info:")]
public string TuesdayDiscounts { get; set; }
[Display(Name = "Wednesday Happy Hour Info:")]
public string WednesdayDiscounts { get; set; }
[Display(Name = "Thursday Happy Hour Info:")]
public string ThursdayDiscounts { get; set; }
[Display(Name = "Friday Happy Hour Info:")]
public string FridayDiscounts { get; set; }
[Display(Name = "Saturday Happy Hour Info:")]
public string SaturdayDiscounts { get; set; }
[Display(Name = "Last Updated")]
public DateTime? LastUpdated { get; set; }
public Address Address { get; set; }
public int? AddressId { get; set; }
[RegularExpression("([1-9][0-9]*)", ErrorMessage = "Must be a number")]
public int? Number { get; set; }
public string StreetName { get; set; }
public string City { get; set; }
public string State { get; set; }
[Required]
public int? ZipCode { get; set; }
public bool IsNew { get; set; }
}
The problem here is that I am getting an empty AddressId with this setup, which is causing an exception when the Save action gets run. This is because the BarForm view is getting passed a ViewModel which has been mapped from a Bar object and the Bar domain model actually has no Address information in it, since it is not the Address model/table.
Is there any way to somehow combine the data from both the Address and Bar models and THEN map them *both* to the same viewModel?
I keep getting a Sequence Contains no Elements error for this line in the Save action:
var addressInDb = _context.Addresses.Single(a => a.Id == bar.AddressId);
I also tried:
var addressInDb = _context.Addresses.Single(a => a.BarId == bar.Id);
Neither work. I understand what the error is saying and have also checked the actual HTML for my hidden Addressid field and it is blank... See code in my BarForm View:
@Html.HiddenFor(m => m.Id)
@Html.HiddenFor(m => m.AddressId)
@Html.AntiForgeryToken()
|
|
|
|
|
If the hidden addressed field is empty it will be because there is no addressed in the model. That is probably down to how you are mapping them, maybe the mapping isn't putting the id from the address object into the addressid in the view model as the two differ. You could try copying this value yourself rather than getting the mapper to do it, or use whatever feature the mapper has for custom mapping.
Before you do that, one thing that may well simplify your code is to do your view model like this
public class BarFormViewModel
{
public Address Address {get; set;}
public Bar Bar {get; set;}
}
That way you don't need to "flatten" two objects into one, and you remove a lot of field duplication also. So when creating your viewmodel you just do
model.Address = addressFromDb;
model.Bar = barFromDb;
You'll need to amend your view as required also, but that is the better way to handle your problem.
|
|
|
|
|
Hi all I am having my print code as follows
public void print()
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = "SnagIt 10";
pd.Print();
}
catch (Exception Ee)
{
}
}
Which works fine when I build and run directly from the application, but when I host my application to my IIS I am unable to print to Snag IT what might stopping this to happen can some one tell.
|
|
|
|
|
Is the SnagIt 10 printer accessible from the IIS server?
|
|
|
|
|
hi richard thanks for the reply you can use this code also pd.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
XPS document is access from IIS .
|
|
|
|
|
Have you checked if user authorized for printing? The standard user for IIS is very thin and can't access almost nothing outside IIS...
Check the machine's log for possible errors/warnings...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
hi Kornfeld,
thanks for the reply but i have check all the possible ways there no error in eventviewer(machine log). permission is given to IIS user.
it's better if you run the same code from your system then you understand the problem very well it's small code
|
|
|
|
|
When you deploy your code, it runs under a specific user account on the server, as configured in the properties of the application pool. That user account most likely doesn't have any printers configured - not even the ubiquitous "XPS" printer. You might be able to resolve the problem by copying some registry keys, as described in this MS KB article[^], but you'll need to know the SID of the AppPool user in order to copy the keys to the correct account.
Also, remember you're printing on the server. If you're expecting the output to appear on the client's printer, you're out of luck.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
salam i make a simple user login form so i want to attach database how i can do
|
|
|
|
|
|
WHEN I AM GOING TO INSTALL ANY SOFTWARE THEN THIS ERROR MESSAGE GIVE:
THE SERVICE DID NOT RESPOND TO THE START OR CONTROL REQUEST IN A TIMLY FASION
|
|
|
|
|
Good day friends! Am having problem with my asp.net project. I have two buttons on the web page. One save to “Temp Files” and the other save to “UploadedImgs”. Saving to the “Temp Files” folder do not raise any exception but saving to the “UploadedImgs” folder causes an exception which says “Could not find a part of the path 'D:\ASP.Net Practical\Website\Site1\ UploadedImgs \'.” To me, the path is 100% correct. So please, does anyone has solution to this problem? Any help will be appreciated.
Below is the code am using.
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim imgext As String = Path.GetExtension(FileUpload1.PostedFile.FileName) 'get image extension
Dim Imgname As String = Path.GetFileName(FileUpload1.PostedFile.FileName) 'get image name
Dim imgpath As String = "\ASP.Net Practical\Website\Site1\ UploadedImgs \" 'get local disk folder path
FileUpload1.PostedFile.SaveAs(Server.MapPath(imgpath + Imgname + imgext))
End Sub
|
|
|
|
|
Clean the save filename first, remove or strip invalid chars, then build the path based on a virtual path, not a physical path. The path will then be converted to a physical path with the Drive letter and all.
Dim fileName as String = Clean_FileName(avatarName.ToLower() + oFileExt)
Dim path as string = Path.Combine(Server.MapPath("~/Images/avatars/customers"), fileName)
Public Shared Function Clean_FileName(ByVal strIn As String) As String
' Replace invalid characters with empty strings.
Try
Return Regex.Replace(strIn, "[^\w.@-_]", "", RegexOptions.None, TimeSpan.FromSeconds(1.5))
Catch As RegexMatchTimeoutException
Return String.Empty
End Try
End Function
|
|
|
|
|
Solved: Thanks. I found the solution after so many trials. I think I should share this so that anyone with such problem could resolve it with ease. The problems was from my webpage submitting an empty filename because of the page load event. So, the solution to this problem is ensure that the uploaded filename is intact before calling the SaveAs command.
Once again, thanks for your reply.
Cheers!
|
|
|
|
|
Well yes that's a good idea.
But the way your mapping out the path may backfire on you when you publish your web app for production use.
Uploading files of anything requires good knowledge of how it works. There about 5 ways to do it to my knowledge.
I don't use the file name of the file anymore, for now I assign my own name to the file. Later on down the road, as users keep uploading the same file with different names, you will have gigs of files sitting in the folder, and the project size will radically expand in size over the course of time. Then what? That's another topic for discussion.
|
|
|
|