i need a web api in which multiple file upload using Type table
Loading
i need a web api in which multiple file upload using Type table
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sandeep KumarPosted Jun 13, 2023, 11:15 AM
Where is issue can u see my code
public List Pms_INSERT_UPDATE_DATA(JObject jsonParam, int UserId)
returnVal = new List();
{
DataTable DtPhoto = new DataTable();
DtPhoto.Columns.Add("FilePath", typeof(System.String));
DtPhoto.Columns.Add("PhotoTag", typeof(System.String));
List
int ID = (int)jsonParam["ID"];
int StationId = (int)jsonParam["StationId"];
int UnitId = (int)jsonParam["UnitId"];
int OutageTypeId = (int)jsonParam["OutageTypeId"];
int ZoneId = (int)jsonParam["ZoneId"];
string FinYear = (string)jsonParam["FinYear"];
string Photo_Tag = (string)jsonParam["PhotoTag"];
var httpRequest = HttpContext.Current.Request;
var filePath = string.Empty;
foreach (string file in httpRequest.Files)
{
var postedFile = httpRequest.Files[file];
string Extension = Path.GetExtension(postedFile.FileName);
filePath = FilePath + Guid.NewGuid() + Extension;
postedFile.SaveAs(filePath);
DtPhoto.Rows.Add(filePath, Photo_Tag);
try
{
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = DBProcedure.SP_InsertUpdatePmsData;
cmd.Parameters.Add("@PmsDataID ", SqlDbType.Int).Value = ID;
cmd.Parameters.Add("@StationID", SqlDbType.Int).Value = StationId;
cmd.Parameters.Add("@UnitID", SqlDbType.Int).Value = UnitId;
cmd.Parameters.Add("@ZoneID", SqlDbType.Int).Value = ZoneId;
cmd.Parameters.Add("@OutageTypeID", SqlDbType.Int).Value = OutageTypeId;
cmd.Parameters.Add("@FinYear", SqlDbType.NVarChar).Value = FinYear;
cmd.Parameters.Add("@ImageList", SqlDbType.Structured).Value = DtPhoto;
cmd.Parameters.Add("@Photo_Tag", SqlDbType.NVarChar).Value = Photo_Tag;
cmd.Parameters.Add("@CreatedBy", SqlDbType.Int).Value = UserId;
cmd.Parameters.Add("@ReturnVal", SqlDbType.Int).Value = 0;
cmd.Parameters["@ReturnID"].Direction = ParameterDirection.InputOutput;
cmd.Parameters["@ReturnPmsDataID"].Direction = ParameterDirection.InputOutput;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
returnVal.Add(Convert.ToInt32(cmd.Parameters["@ReturnVal"].Value.ToString()));
}
}
}
catch (Exception ex)
{
}
return returnVal;
}
Sandeep KumarPosted Jun 13, 2023, 11:04 AM
my type table
CREATE TYPE [dbo].[ImageListType] AS TABLE(
[FilePath] [varchar](500) NULL,
[PhotoTag] [varchar](50) NULL
)
Amit MohantyPosted Jun 13, 2023, 10:49 AM
Define the table type in SQL Server:
Create a stored procedure that accepts the table type as a parameter:
Define the UploadedFile class to represent each uploaded file:
Your web API project, define an endpoint that accepts multiple file uploads using the table type parameter:
You may need to modify the code based on your specific requirements, such as error handling, file validation, and saving files to a specific location or store file information in a database.