i'm using ajaxfileupload in my asp.net project
i to get list of uploaded files and save them in database
but i don't know how i can get which files are uploading when i press on upload button
protected void AjaxFileUpload1_UploadComplete1(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string filePath = MapPath("~/images/") + System.IO.Path.GetFileName(e.FileName);
AjaxFileUpload1.SaveAs(filePath);
}
Related
Good day.
I have a Windows forms application (C#).
With the "open file dialog" I can select a .pdf file.
Selected .pdf file is copied and stored in a pre-determined destination.
File path of selected .pdf file is stored in an SQL database.
What is the function/method to open a .pdf file (in axAcroPDF...), which is stored in a folder and its file path is stored in a database?
This is what I have, code vise:
private void txtST1Cap_DoubleClick(object sender, EventArgs e)
{
SavedDocumentPath1 = #"XXX\";
using (OpenFileDialog OpenFileDialog1 = new OpenFileDialog() { ValidateNames = true, Multiselect = false, Filter = "PDF|*.pdf" })
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
//display PDF in reader
OpenedDocument1 = openFileDialog1.FileName;
axAcroPDF1ST1.src = openFileDialog1.FileName;
//code for getting REF No. from opened file name
OpenedDocumentREF = Path.GetFileName(openFileDialog1.FileName);
REFfromOpenedDocument = OpenedDocumentREF.Substring(0, 12);
txtST1Cap.Text = REFfromOpenedDocument;
//destination of to-be saved document
SavedDocLoc1 = (SavedDocumentPath1 + Path.GetFileName(openFileDialog1.FileName));
lblST1CapLocation.Text = SavedDocLoc1;
}
}
private void btnST1Cap_Click(object sender, EventArgs e)
{
openFileDialog1.FileName=SavedDocLoc1;
axAcroPDF1ST1.src = openFileDialog1.FileName;
}
Button Clicl btnST1Cap does not work.
Thank you.
I was almost correct.
So, if one wants to open a PDF document in a "default program" System.Diagnostics.Process,... is used:
private void btnST1Cap_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(lblST1CapLocation.Text);
}
As mentioned, this opens a default .pdf browser.
I wanted, to open it in my form (in axAcroPDF...):
private void btnST1Cap_Click(object sender, EventArgs e)
{
axAcroPDF1ST1.src = lblST1CapLocation.Text;
}
Yaaaay 4 ME!
In above cases "lblST1CapLocation.Text" is the label where file path is stored.
Direct file path can be inserted if wished:
System.Diagnostics.Process.Start(#"c:\myPdf.pdf");
I want to use file upload control in dnn module programming.
I know there is DnnFilePicker in dnn, but I want a simple code that each user can upload a file and after that can display, edit and delete it.
There is this code but is not complete.
<%# Register TagPrefix="dnn" Assembly="DotNetNuke.Web" Namespace="DotNetNuke.Web.UI.WebControls" %>
<dnn:DnnFilePicker runat="server" ShowFolders="false" ID="fpUserFiles" FileFilter="pdf,gif,jpg" />
In Page_Load event, set the folder:
// Limit filepath to user's folder
fpUserFiles.FilePath = FolderManager.Instance.GetUserFolder(User).FolderPath;
what should i do?
If you have some sort of Save event on your module view, you simply get the FileId of the file that was selected by the user to save it in the database:
protected void btnSubmit_Click(object sender, EventArgs e)
{
ModelData model = new ModelData {
FileId = fpUserFiles.FileID
};
// TODO: Save your model data
}
In your Page_Load event, you can also load model data (if user is editing an existing model) by setting the fileID on the File Picker. That will pre-select the file in the picker control.
fpUserFiles.FileID = model.FileId
To use the fileId in another module view, you can get it from your model data and get the attributes of the file like this example:
FileInfo fi = (FileInfo)FileManager.Instance.GetFile(model.FileId);
if (fi != null)
{
pic.ImageUrl = "/" + _currentPortal.HomeDirectory + "/" + fi.RelativePath;
}
With this code my problem is resolved.
each user can upload its files in its folder.
protected void Page_Load(object sender, EventArgs e)
{
username = UserController.GetCurrentUserInfo().Username.ToString();
}
protected void Button1_Click1(object sender, System.EventArgs e)
{
var folder = Server.MapPath("~/uploads/Company/" + username);
if (this.FileUpload1.HasFile)
{
Directory.CreateDirectory(folder);
this.FileUpload1.SaveAs(folder + "/" + this.FileUpload1.FileName);
}
}
Hi I am trying to save only the path of a file using fileupload . On clicking the button I want only the complete path that the user has selected into the file upload to be stored into the database. Just for testing purposes I am using labels in the code below but ultimately I will connect it to a data base.I only need to store the path selected by the user and not the file.
HTML
C# that I have been trying but not working
protected void Button1_Click(object sender, EventArgs e)
{
string g = FileUpload1.FileName;
string b =Convert.ToString(FileUpload1.PostedFile.InputStream);
//string filepath = Path.GetFullPath(FileUpload1.FileName.toString());
Label1.Text = g;
Label2.Text =b;
}
change your code as below:
protected void Button1_Click(object sender, EventArgs e)
{
string g = Server.MapPath(FileUpload1.FileName);
string b =Convert.ToString(FileUpload1.PostedFile.InputStream);
//string filepath = Path.GetFullPath(FileUpload1.FileName.toString());
Label1.Text = g;
Label2.Text =b;
}
You can't.
See also here: How can I get file.path in plupload?
If I get you correctly, this is some kind of intranet application?
If this needs to work within a closed domain, you might as well think about a desktop application instead.
You need a path for save file? Try this:
this.MapPath("~")
or
this.yourUploadFile.PostedFile.SaveAs(this.MapPath("~") + "YOUR FOLDER + NAME");
I have a Master page with an iFrame.
Tickets.aspx has this Master. General.aspx is without any Master and loads inside the iFrame.
Both the pages have buttons to download files.
When downloading file from General.aspx, it shows this error.
Unable to evaluate expression because the code is optimized or a
native frame is on top of the call stack.
General.aspx.cs:
protected void View (object sender, CommandEventArgs e)
{
string sFile = "~/Attachments/"+(e.CommandArgument.ToString());
if(File.Exists(Server.MapPath(sFile)))
{
Response.Redirect("/Forms/DownloadFile.aspx?file="+sFile); //ERROR HERE
}
}
DownloadFile.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
string sPath = Server.MapPath(Request.QueryString["file"]);
FileInfo file = new FileInfo();
if(file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition","attachment; filename="+file.Name);
Response.AddHeader("Content-Length",file.Length.ToString());
Response.ContentType="application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
}
DownloadFile.aspx uses the same Master and has the code. There is no problem when downloading from Tickets.aspx. I thought this could be due to the iframe. So I created a similar download page without a master. But still the same error.
How can I resolve this.
I am using a asyncfileupload control to upload a file there i am taking the path in a view state like this:
protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string name = System.IO.Path.GetFileName(e.FileName);
string dir = Server.MapPath("upload_eng/");
string path = Path.Combine(dir, name);
ViewState["path"] = path;
engcertfupld.SaveAs(path);
}
Now when i am trying to save that path in a buttonclick event i am not getting the value of viewstate:
protected void btnUpdate_Click(object sender, EventArgs e)
{
string filepath = ViewState["path"].ToString(); // GETTING NULL in filepath
}
In this filepath i am getting null actually i am getting error NULL REFERENCE EXCEPTION
What can I do now?
Put the Path value in the Session object instead of the ViewState, like this:
protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
....
string path = Path.Combine(dir, name);
Session["path"] = path;
}
Then in the Button Click:
protected void btnUpdate_Click(object sender, EventArgs e)
{
if (Session["path"] != null)
{
string filepath = (string) Session["path"];
}
}
I guess the upload process is not a "real" postback, so the ViewState will not be refreshed client side and won't contain the path upon click on btnUpdate_Click
What you should do is use the OnClientUploadComplete client-side event to retrieve the uploaded file name, and store it in a HiddenField that will be posted on the server on btnUpdate_Click.
Here is a complete example where the uploaded file name is used to display an uploaded image without post-back :
http://www.aspsnippets.com/Articles/Display-image-after-upload-without-page-refresh-or-postback-using-ASP.Net-AsyncFileUpload-Control.aspx