Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I put my webform(UserPage.aspx) in a rootfolder named UpdatePage, and I'm Uploading my Videos In different root folder named: UploadedVideos. Everything is working fine. but when I'm retrieving the Path of the video from the sql server and pass it to the video player in the Gridview, it is looking for the video in UpdatePage/UploadVideos/filename.mp4 instead of root folder UploadVideos/Filename.mp4.
How to solve the issue??

Backend Code:
C#
// Backend code for uploading file and saving path
if (fileupload1.HasFile && fileupload1.PostedFile != null && fileupload1.PostedFile.FileName != "")
{
	Bal objBal = new Bal();
	try
	{
		string filename = Path.GetFileName(fileupload1.PostedFile.FileName);
		fileupload1.PostedFile.SaveAs(Server.MapPath("~/UploadedVideos/" + filename));
		string filepathtostore = string.Format("UploadedVideos/"+filename);
		objBal.VideoFilePath = filepathtostore;
		objBal.Description = txtDesc.Text.Trim();
		objBal.Course = dropdownlist1.SelectedItem.ToString();
		objBal.filetype = dropdownlist2.SelectedItem.ToString();
		int result = objBal.AdminUploadPhysicsVideoBalFunc(objBal);
		if(result>0)
		{
			labelmsg.Visible = true;
			labelmsg.ForeColor = System.Drawing.Color.Green;
			labelmsg.Text = "Video File Updated Successfully";
		}
		else
		{
			labelmsg.Visible = true;
			labelmsg.ForeColor = System.Drawing.Color.Red;
			labelmsg.Text = "Can't Upload File Try Again.";
		}
		BindVideoPanel();
	}
	catch(Exception ex)
	{
		throw ex;
	}
	finally
	{
		objBal = null;
	}
}
 
// Backend code for binding Gridview
private void BindVideoPanel() 
{
	DataSet ds = new DataSet();
	Bal objBal = new Bal();
	try
	{
		ds = objBal.BindVideoPanelBalFunc();
		VideoGridView.DataSource = ds;
		VideoGridView.DataBind();
	}
	catch(Exception ex)
	{
		throw ex;
	}
	finally
	{
		objBal = null;
	}
}
Frontend code:
HTML
<columns>
                       <asp:templatefield headertext="ID">
                           <itemtemplate>
                               <asp:label id="lblVideoId" runat="server" text="<%#Eval("Id") %>">
                           
                       

                       <asp:templatefield headertext="Course">
                           <itemtemplate>
                               <asp:label id="lblVideoCourse" runat="server" text="<%#Eval("Course") %>">
                           
                       

                       <asp:templatefield headertext="Description">
                           <itemtemplate>
                               <asp:label id="lblVideoDesc" runat="server" text="<%#Eval("VideoDesc") %>">
                           
                       
                       
                       <asp:templatefield headertext="Video Preview">
                           <itemtemplate>
                              
                                  
                              
                           
                       
                       
                       <asp:templatefield headertext="Actions">
                           <itemtemplate>
                               <asp:linkbutton id="lnkDelete" runat="server" commandname="Delete"><span class="fa fa-trash"></span>


What I have tried:

I've tried passing the path directly but not working either way.
Posted
Updated 27-Apr-20 6:06am
v2
Comments
MadMyche 27-Apr-20 12:01pm    
After going through the code and looking at your original question... it appears that where the problem may be is in code you did not provide: BindVideoPanelBalFunc.
You may want to use the "Improve Question" widget above to add in that block of code.

1 solution

Your uploaded HTML is missing a (critical) section; however the question seems very confused. You refer to the "root" folder being UpdatePage; but then to another root folder being UploadedVideos. By definition, your website has ONE root folder - that's why it's called the root!

If your site is hosted at UpdatePage, you won't be able to access anything in UploadedVideos UNLESS either there's a separate domain (or subdomain) with UploadedVideos as its root, OR your webserver allows accessing the server above the site folder - which is (a) very unusual and (b) very dangerous. To resolve, I'd strongly recommend you move UploadedVideos so that it's a subfolder of UpdatePage - your code will then work - though you will need to remove the ~\ in the Server.MapPath call to get the video filename.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900