Hi I am working on a MVC Project in which I have a reports page where user can view reports with the use of a report viewer.
I need to set the page size dynamically for a report, I tried many ways to solve this but I couldn’t.
I can change the ReportViewer Size with this code
rptviewer.Height = Unit.Pixel(520);
Kindly help me in with the following queries.
1.Is it possible to change the SSRS report page height using C# Code?
2.Is it possible to change the paper size in the runtime?
My Previous workarounds
<-------- 1 --------->
System.Drawing.Printing.PageSettings pg = new System.Drawing.Printing.PageSettings();
pg.Margins.Top = 0;
pg.Margins.Bottom = 0;
pg.Margins.Left = 0;
pg.Margins.Right = 0;
System.Drawing.Printing.PaperSize size = new PaperSize();
size.RawKind = (int)PaperKind.A5;
pg.PaperSize = size;
rptviewer.SetPageSettings(pg);
ViewBag.ReportViewer = rptviewer;
return View("_ReportView");
<-------- 2 --------->
System.Drawing.Printing.PageSettings MyPageSize= new System.Drawing.Printing.PageSettings();
MyPageSize.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 17, 12);
rptviewer.SetPageSettings(MyPageSize);
<-------- 3 --------->
var setup = rptviewer.GetPageSettings();
setup.PaperSize.Height = 1500;
rptviewer.SetPageSettings(setup);
None of the above logic worked for me :-(
The thing is, In order to control the page size in the rendering process we need to pass the proper Device Information Settings to the report at run time. This will work for physical page oriented renders like PDF, Image, etc. This is a simple Xml string that can be passed as a parameter to the report in order to control these settings. Each export type has a different set of properties that can be overridden and controlled in this way.
In the following example, an export to PDF is performed and passes the page height and width to match an A4 paper size as the targeted device (line 66):
private void RenderReportToClient()
{
//set credentials
RSExecuteProxy.ReportExecutionService rs = new RSExecuteProxy.ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
RSProxy.ReportingService2005 rsInfo = new RSProxy.ReportingService2005();
rsInfo.Credentials = System.Net.CredentialCache.DefaultCredentials;
// init render args
byte[] result = null;
string reportPath = rptViewer.ServerReport.ReportPath;
string format = "PDF";
string historyId = null;
string encoding;
string mimeType;
string extension;
RSExecuteProxy.Warning[] warnings = null;
string[] streamIDs = null;
//init exec info
RSExecuteProxy.ExecutionInfo execInfo = new RSExecuteProxy.ExecutionInfo();
RSExecuteProxy.ExecutionHeader execHeader = new RSExecuteProxy.ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
//get report
execInfo = rs.LoadReport(reportPath, historyId);
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
//get parameter info
ReportParameterInfoCollection parameters = rptViewer.ServerReport.GetParameters();
//figure out how many parameters we will have
//those with multi-value will need there own ParameterValue in the array
int paramCount = 0;
foreach (ReportParameterInfo pramInfo in parameters)
{
paramCount += pramInfo.Values.Count;
}
RSExecuteProxy.ParameterValue[] prams = new SSRSWeb.RSExecuteProxy.ParameterValue[paramCount];
int currentPramPosition = 0;
//set pram values
foreach (ReportParameterInfo pramInfo in parameters)
{
foreach (string pramValue in pramInfo.Values)
{
prams[currentPramPosition] = new SSRSWeb.RSExecuteProxy.ParameterValue();
prams[currentPramPosition].Label = pramInfo.Name;
prams[currentPramPosition].Name = pramInfo.Name;
prams[currentPramPosition].Value = pramValue;
currentPramPosition++;
}
}
rs.SetExecutionParameters(prams, "en-US");
//build the device settings (A4 8.3 × 11.7)
string deviceInfo = string.Format("<DeviceInfo><PageHeight>{0}</PageHeight><PageWidth>{1}</PageWidth></DeviceInfo>", "11.7in", "8.3in");
//get report bytes
result = rs.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
Response.ClearContent();
Response.AppendHeader("Content-Disposition", "inline;filename=report.pdf");
Response.AppendHeader("content-length", result.Length.ToString());
Response.ContentType = "application/pdf";
Response.BinaryWrite(result);
Response.Flush();
Response.Close();
}
When the report is saved you can view the PDF and examine the properties and notice that the page height and width is 8.3in x 11.7in as specified.
Related
I want to load in a JPEG file and print it with Aspose.Pdf in C# (.net Framework 4.8). The code I currently have is:
public void PrintImage(string fileToPrint, string printerName, string jobName)
{
System.Drawing.Image srcImage = System.Drawing.Image.FromFile(fileToPrint);
int h = srcImage.Height;
int w = srcImage.Width;
var doc = new Document();
var page = doc.Pages.Add();
var image = new Image();
image.File = (fileToPrint);
page.PageInfo.Height = (h);
page.PageInfo.Width = (w);
page.PageInfo.Margin.Bottom = (0);
page.PageInfo.Margin.Top = (0);
page.PageInfo.Margin.Right = (0);
page.PageInfo.Margin.Left = (0);
page.Paragraphs.Add(image);
var viewer = new PdfViewer(doc);
PrintUsingViewer(viewer, printerName, jobName);
}
private static void PrintUsingViewer(PdfViewer viewer, string printerName, string jobName)
{
viewer.AutoResize = true; // Print the file with adjusted size
viewer.AutoRotate = true; // Print the file with adjusted rotation
viewer.PrintPageDialog = false; // Do not produce the page number dialog when printing
var ps = new System.Drawing.Printing.PrinterSettings();
var pgs = new System.Drawing.Printing.PageSettings();
ps.PrinterName = printerName;
viewer.PrinterJobName = jobName;
viewer.PrintDocumentWithSettings(pgs, ps);
viewer.Close();
}
When I save the document instead of printing and look at it, it seems fine (the image is added). However, when trying to print the image it is not printed and the page is just blank..
I would like to print without first saving the document as a PDF and then trying to print that saved PDF. Does anyone see what I am doing wrong?
The solution was adding this line of code
doc.ProcessParagraphs();
right after this line:
page.Paragraphs.Add(image);
So the code now becomes
public void PrintImage(string fileToPrint, string printerName, string jobName)
{
System.Drawing.Image srcImage = System.Drawing.Image.FromFile(fileToPrint);
int h = srcImage.Height;
int w = srcImage.Width;
var doc = new Document();
var page = doc.Pages.Add();
var image = new Image();
image.File = (fileToPrint);
page.PageInfo.Height = (h);
page.PageInfo.Width = (w);
page.PageInfo.Margin.Bottom = (0);
page.PageInfo.Margin.Top = (0);
page.PageInfo.Margin.Right = (0);
page.PageInfo.Margin.Left = (0);
page.Paragraphs.Add(image);
doc.ProcessParagraphs();
var viewer = new PdfViewer(doc);
PrintUsingViewer(viewer, printerName, jobName);
}
private static void PrintUsingViewer(PdfViewer viewer, string printerName, string jobName)
{
viewer.AutoResize = true; // Print the file with adjusted size
viewer.AutoRotate = true; // Print the file with adjusted rotation
viewer.PrintPageDialog = false; // Do not produce the page number dialog when printing
var ps = new System.Drawing.Printing.PrinterSettings();
var pgs = new System.Drawing.Printing.PageSettings();
ps.PrinterName = printerName;
viewer.PrinterJobName = jobName;
viewer.PrintDocumentWithSettings(pgs, ps);
viewer.Close();
}
Now the image is printed correctly!
I have the following code:
private void CreateExcel(string fileName)
{
var operationDate = System.DateTime.ParseExact(txtStartDate.Text, "dd/MMM/yyyy", CultureInfo.CurrentCulture);
var ds1 = new _spAvailabilityEventDailyReport1TableAdapter();
var ds2 = new _spAvailabilityEventDailyReport2TableAdapter();
var ds3 = new _spAvailabilityEventDailyReport3TableAdapter();
var ds4 = new _spAvailabilityEventTotalTableAdapter();
var ds5 = new _spAvailabilityNoteDailyReportTableAdapter();
var ds6 = new _spAvailabilityDailyReportTableAdapter();
var ds7 = new _spAvailabilityReadingTotalTableAdapter();
var ds8 = new _spAvailabilityEventSum1TableAdapter();
var ds9 = new _spAvailabilityEventSum2TableAdapter();
var ds10 = new _spAvailabilityEventSum3TableAdapter();
//default margin setting
string outputType = "Excel";
string pageHeight = "11.69in";
string pageWidth = "8.27in";
string marginTop = "0.3937in";
string marginBottom = "0.3937in";
string marginLeft = "0.3937in";
string marginRight = "0.3937in";
string reportPath = Server.MapPath("~/rdlc/dailyavailability.rdlc");
try
{
//search setting margin report & kind output export -> for parameter 2nd render RDLC
var xml = System.IO.File.ReadAllText(reportPath);
var matches = Regex.Matches(xml, #"<(?<property>PageHeight|PageWidth|TopMargin|BottomMargin|LeftMargin|RightMargin)>(?<value>[^<]+)</\k<property>>", RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
if (!match.Success)
continue;
switch (match.Groups["property"].Value)
{
case "PageHeight":
pageHeight = match.Groups["value"].Value;
break;
case "PageWidth":
pageWidth = match.Groups["value"].Value;
break;
case "TopMargin":
marginTop = match.Groups["value"].Value;
break;
case "BottomMargin":
marginBottom = match.Groups["value"].Value;
break;
case "LeftMargin":
marginLeft = match.Groups["value"].Value;
break;
case "RightMargin":
marginRight = match.Groups["value"].Value;
break;
}
}
}
catch (System.Exception) { }
string reportType = string.IsNullOrEmpty(outputType) ? "Excel" : outputType.Trim().ToUpper();
string encoding;
string deviceInfo = string.Format(#"<DeviceInfo>
<OutputFormat>{6}</OutputFormat>
<PageWidth>{0}</PageWidth>
<PageHeight>{1}</PageHeight>
<MarginTop>{2}</MarginTop>
<MarginLeft>{3}</MarginLeft>
<MarginBottom>{4}</MarginBottom>
<MarginRight>{5}</MarginRight>
</DeviceInfo>", pageWidth, pageHeight, marginTop, marginLeft, marginBottom, marginRight, reportType);
var rds = new ReportDataSource("dsAvailabilityEventDailyReport1", (DataTable)ds1.GetData(operationDate)); //fill data report in parameter
var rds2 = new ReportDataSource("dsAvailabilityEventDailyReport2", (DataTable)ds2.GetData(operationDate)); //fill data report in parameter
var rds3 = new ReportDataSource("dsAvailabilityEventDailyReport3", (DataTable)ds3.GetData(operationDate)); //fill data report in parameter
var rds4 = new ReportDataSource("dsAvailabilityEventTotal", (DataTable)ds4.GetData(operationDate)); //fill data report in parameter
var rds5 = new ReportDataSource("dsAvailabilityNoteDailyReport", (DataTable)ds5.GetData(operationDate)); ///fill data report in parameter
var rds6 = new ReportDataSource("dsAvailabilityDailyReport", (DataTable)ds6.GetData(operationDate)); //fill data report in parameter
var rds7 = new ReportDataSource("dsAvailabilityReadingTotal", (DataTable)ds7.GetData(operationDate)); //fill data report in parameter
var rds8 = new ReportDataSource("dsAvailabilityEventSum1", (DataTable)ds8.GetData(operationDate)); //fill data report in parameter
var rds9 = new ReportDataSource("dsAvailabilityEventSum2", (DataTable)ds9.GetData(operationDate)); //fill data report in parameter
var rds10 = new ReportDataSource("dsAvailabilityEventSum3", (DataTable)ds10.GetData(operationDate)); //fill data report in parameter
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string extension = string.Empty;
// Setup the report viewer object and get the array of bytes
var report = new LocalReport();
report.ReportPath = reportPath;
report.DataSources.Add(rds); // Add datasource here
report.DataSources.Add(rds2); // Add datasource here
report.DataSources.Add(rds3); // Add datasource here
report.DataSources.Add(rds4); // Add datasource here
report.DataSources.Add(rds5); // Add datasource here
report.DataSources.Add(rds6); // Add datasource here
report.DataSources.Add(rds7); // Add datasource here
report.DataSources.Add(rds8); // Add datasource here
report.DataSources.Add(rds9); // Add datasource here
report.DataSources.Add(rds10); // Add datasource here
//set parameter report (jika ada)
report.SetParameters(new List<ReportParameter>
{
//new ReportParameter("FacilitySubClassID", facilitySubClassId.ToString()),
new ReportParameter("OperationDate", operationDate.ToString())
});
byte[] bytes = report.Render(reportType, deviceInfo, out mimeType, out encoding, out extension, out streamIds, out warnings);
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "." + extension + "\"");
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download
}
I have a sub-report on my rdlc report,, when i tried to export it to excel. The error message appear on excel file (sub-report section).
"Data retrieval failed for the subreport, 'srAvailabilityList', located at: C:\Users\xxxxx\Documents\Visual Studio 2010\Projects\coco\rdlc\availabilityreading.rdlc. Please check the log files for more information."
The sub-report is using ds6 and ds7.
My questions are:
How can I retrieve the data in the sub-report?
Where I can find the log files?
Found the answer:
void MySubreportEventHandler(object sender, SubreportProcessingEventArgs e)
{
var operationDate = System.DateTime.ParseExact(txtStartDate.Text, "dd/MMM/yyyy", CultureInfo.CurrentCulture);
var ds6 = new _spAvailabilityDailyReportTableAdapter();
var ds7 = new _spAvailabilityReadingTotalTableAdapter();
var rds6 = new ReportDataSource("dsAvailabilityDailyReport", (DataTable)ds6.GetData(operationDate)); //isi data report di parameter kedua
var rds7 = new ReportDataSource("dsAvailabilityReadingTotal", (DataTable)ds7.GetData(operationDate)); //isi data report di parameter kedua
e.DataSources.Add(rds6);
e.DataSources.Add(rds7);
}
Then add this code before report.SetParameter :
report.SubreportProcessing += new SubreportProcessingEventHandler(MySubreportEventHandler);
I have a master report file and a sub report file.
Master report file calls sub report file.
Let's have a look at the code first.
private void CreatePDF(string fileName)
{
try
{
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
string _strGijunMonth = DateTime.Parse(GijunMonth).ToString("yyyyMM");
byte[] bytes = null;
// Setup the report viewer object and get the array of bytes
ReportViewer viewer = new ReportViewer();
viewer.LocalReport.DataSources.Clear();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportEmbeddedResource = "MasterReport.rdlc";
viewer.LocalReport.EnableExternalImages = true;
DataTable _dt = base.GetDataTable(
"my_procedure"
, _strMainNo
);
_intTotalPage = _dt.Rows.Count * 2;
ReportDataSource _ds = new ReportDataSource();
_ds.Value = _dt;
_ds.Name = "SetData";
viewer.LocalReport.DataSources.Add(_ds);
// sub report event
viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
// print
viewer.RefreshReport();
bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
System.IO.FileStream newFile1 = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
newFile1.Write(bytes, 0, bytes.Length);
newFile1.Close();
}
catch
{
throw;
}
}
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
try
{
string MAINT_NO = e.Parameters["MAINT_NO"].Values[0];
string _strGijunMonth = DateTime.Parse(GijunMonth).ToString("yyyyMM");
// get sub report procedure
DataSet _dsCust_Info = base.GetDataSet(
"my_sub_procedure"
, MAINT_NO
, _strGijunMonth
);
----> by somehow, it should throw error. If so, I should not print error page to pdf.
}
catch (Exception err)
{
}
}
My application calls "CreatePDF" method with file name argument.
Let's say that I have to print to PDF 5 pages.
While calling LocalReport_SubreportProcessing event, some of sub reports have error value in data. So, I throw an error in LocalReport_SubreportProcessing event.
For example, when I say that there are 5 pages and only 1, 2, 3 and 5 pages are okay and the number 4 page should not be printed as PDF.
I wonder how I can delete PDF page which is already created by ReportViewer.
As you can see, LocalReport_SubreportProcessing event comes after creating PDF file.
Anyone has any idea to fix this problem?
Maybe reportViewer.CancelRendering(0);
when you detect an error?
I had an grid view where I had placed an link button to print an report. In this button click event I need to call the SSRS report and need to get the output as PDF file.
I had used this below code,the code is running fine, but I'm unable to see the prompt to open/save pdf file.
protected void btnAuthenticateAndPrint_Click(object sender, EventArgs args)
{
try
{
//Getting Values from grid
LinkButton lb = (LinkButton)sender;
GridViewRow row = (GridViewRow)lb.NamingContainer;
Label lbOrderID = row.FindControl("lbOrderID") as Label;
int OrderId = Convert.ToInt32(lbOrderID.Text);
da = new SqlDataAdapter("Get_PODetails", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddWithValue("#MPDI_ID", OrderId);
ds = new DataSet();
da.Fill(ds, "PO");
if (ds.Tables["PO"].Rows.Count > 0)
{
lblPOId.Text=ds.Tables["PO"].Rows[0]["MPDI_ID"].ToString();
lblVendid.Text = ds.Tables["PO"].Rows[0]["MVDI_ID"].ToString();
lblBranch.Text = ds.Tables["PO"].Rows[0]["MBRI_ID"].ToString();
lblDate.Text = Convert.ToDateTime(ds.Tables["PO"].Rows[0]["MPDI_Date"]).ToString("dd-MM-yyyy");
}
//SSRS Report Print
rs = new RSWebService.ReportingService2005();
rsExec = new REWebService.ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://localhost/ReportServer/ReportService2005.asmx";
rsExec.Url = "http://localhost/ReportServer/ReportExecution2005.asmx";
byte[] Sendresults = null;
byte[] bytes = null;
string historyID = null;
string deviceInfo = #"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
string format = "PDF";
string encoding = null;
string mimeType = null;
string extension = null;
REWebService.Warning[] warnings = null;
string[] streamIDs = null;
string _reportName = #"/FIMO GOF Assets Reports/PURCHASE ORDER";
REWebService.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID);
REWebService.ParameterValue[] parameters = new REWebService.ParameterValue[4];
parameters[0] = new REWebService.ParameterValue();
parameters[0].Name = "MVDI_ID";
parameters[0].Value = lblVendid.Text;
parameters[1] = new REWebService.ParameterValue();
parameters[1].Name = "MBRI_ID";
parameters[1].Value = lblBranch.Text;
parameters[2] = new REWebService.ParameterValue();
parameters[2].Name = "MPDI_Date";
parameters[2].Value = lblDate.Text;
parameters[3] = new REWebService.ParameterValue();
parameters[3].Name = "ReportParameter1";
parameters[3].Value = lblPOId.Text;
rsExec.SetExecutionParameters(parameters, "en-us");
Sendresults = rsExec.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
MemoryStream ms = new MemoryStream(Sendresults);
//To create a PDF
if (format == "PDF")
{
Response.ContentType = "application/pdf";
Response.AddHeader("Content-disposition", "inline;filename=output.pdf");
Response.AddHeader("Content-Length", Sendresults.Length.ToString());
}
Response.OutputStream.Write(Sendresults, 0, Sendresults.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
}
catch(Exception Ex)
{
throw Ex;
}
}
You can use URL access, as described here: http://msdn.microsoft.com/en-us/library/ms154040(v=sql.105).aspx
http://<Server Name>/reportserver?/Sales/YearlySalesSummary&rs:Format=PDF&rs:Command=Render
I have working code that uses signature pad data to create and save a signature bmp image to a file location. My question is: how can I modify this code to insert the image into a SQL Server 2008 image field?
The following from my Controller obtains signature data from a signature tablet and creates a bmp image and saves it to a file location.
[PrincipalPermission(SecurityAction.Demand, Authenticated = true)]
public ActionResult SaveSignature2(IPrincipal principal) {
int userId = ((ScoutIdentity)principal.Identity).UserId.Value;
//Put user code to initialize the page here
SIGPLUSLib.SigPlus sigObj = new SIGPLUSLib.SigPlus();
sigObj.InitSigPlus();
sigObj.AutoKeyStart();
string visitorname = Request.Form["visitorname"];
visitorname = visitorname.Replace(" ", ""); //combines the first name with last name with no spaces
visitorname = visitorname.Trim();
string thevrvIDstr = Request.Form["vrvID"];
int thevrvID = Convert.ToInt32(thevrvIDstr);
//use the same data to decrypt signature
sigObj.AutoKeyData = Request.Form["SigText"];
sigObj.AutoKeyFinish();
sigObj.SigCompressionMode = 1;
sigObj.EncryptionMode = 2;
//Now, get sigstring from client
//Sigstring can be stored in a database if
//a biometric signature is desired rather than an image
sigObj.SigString = Request.Form["hidden"];
if (sigObj.NumberOfTabletPoints() > 0) {
sigObj.ImageFileFormat = 0;
sigObj.ImageXSize = 500;
sigObj.ImageYSize = 150;
sigObj.ImagePenWidth = 8;
sigObj.SetAntiAliasParameters(1, 600, 700);
sigObj.JustifyX = 5;
sigObj.JustifyY = 5;
sigObj.JustifyMode = 5;
long size;
byte[] byteValue;
sigObj.BitMapBufferWrite();
size = sigObj.BitMapBufferSize();
byteValue = new byte[size];
byteValue = (byte[])sigObj.GetBitmapBufferBytes();
sigObj.BitMapBufferClose();
System.IO.MemoryStream ms = new System.IO.MemoryStream(byteValue);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
String path;
path = System.AppDomain.CurrentDomain.BaseDirectory;
path = path + "/uploadFiles/Signatures/"+thevrvIDstr+".bmp";
img.Save(path, System.Drawing.Imaging.ImageFormat.Bmp);
ViewData["Result"] = ("Image saved successfully to " + path);
}
else {
ViewData["Result"] = "signature has not been returned successfully!";
}
ViewData["Result"] = sigObj.SigString;
//return RedirectToAction("vrSignIn");
return View();
}
I also have code elsewhere in my controller that gets an uploaded file and inserts it into the database. This code works OK.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadTempFiles(string id, string u)
{
//this method temporarily stores files
string userIdString = Cryptographer.DecryptSymmetric("RijndaelManaged", SecurityImpl.UrlToBase64(u));
int userId = Convert.ToInt32(userIdString);
if (Request.Files.Count > 0)
{
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
int contentlength = file.ContentLength;
byte[] b = new byte[contentlength];
Stream s;
s = file.InputStream;
s.Read(b, 0, contentlength);
VisitRequest.AddVisitorSignature(userId, b);
}
}
return View("UploadFiles");
}
I'm thinking that I can use some part of the second code to interrupt the image creation process in the first code and insert the image into the database INSTEAD of saving the image to a file location. I don't know how to do that.
I had same problem, and I solved it:
Comment these three lines:
//path = System.AppDomain.CurrentDomain.BaseDirectory;
//path = path + "/uploadFiles/Signatures/"+thevrvIDstr+".bmp";
//img.Save(path, System.Drawing.Imaging.ImageFormat.Bmp);
Convert image to String data (assumed that your variable 'strSignature' was declared before):
strSignature = img.ToString();
Save it with your Stored Procedure.
Hope this help you!